I'm trying to get address using place_id in hindi but I'm getting some special characters. Please someone help me.
<?php
$url = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJLbZ-NFv9DDkRzk0gTkm3wlI&language=hi&key=AIzaSyBt7SRPMKW4pWc06NwuzFNCErXxnIlyEIY';
$headers = array(
'Content-Type: application/json'
);
// OPEN CONNECTION
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if(curl_errno($ch)){
echo curl_error($ch);
}
// Close connection
curl_close($ch);
$result=json_decode($result);
//pr($result);
echo "<pre>";print_r($result->result->formatted_address);
?>
Related
I'm trying to submit a POST request with JSON data to an api endpoint. The endpoint requires a querystring passing the api credentials, but also requires the JSON data to be POSTed.
When I try to do this with PHP cURL as shown below, the querystring is apparently removed - thus the api is rejecting the request due to missing api key.
I can do this easily with Postman when testing access to the api endpoint.
How can I make the cURL request include both the querystring AND the JSON POST body?
Example code:
// $data is previously defined as an array of parameters and values.
$url = "https://api.endpoint.url?api_key=1234567890";
$ch = curl_init();
$json = json_encode($data);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($json)
]
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
You are doing almost right.
Sometimes you need to relax SSL verification.
Otherwise, update php ca bundle:
https://docs.bolt.cm/3.7/howto/curl-ca-certificates
Add the following:
$headers = array(
"Content-type: application/json;charset=UTF-8",
"Accept-Encoding: gzip,deflate",
"Content-length: ".strlen($json),
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_ENCODING, "identity, deflate, gzip");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
Sometimes you need to change encoding too:
$result = utf8_decode($result);
And check the returning data.
I'm trying to query multiple domain name availability using php and curl but I can't seem to get a valid response back.
API:
https://api.godaddy.com/v1/domains/available
Documentation here:
https://developer.godaddy.com/doc/endpoint/domains#/v1/availableBulk
My code is below. Any help would be much appreciated.
$domains = array("name.com", "test.com", "monkey123er.com", "Sally123.co");
$domainsJSON = json_encode($domains);
// see GoDaddy API documentation - https://developer.godaddy.com/doc
// url to check domain availability
$url = "https://api.godaddy.com/v1/domains/available".
// see GoDaddy API documentation - https://developer.godaddy.com/doc
// set your key and secret
$header = array(
'Authorization: sso-key XXX:XXXX'
);
//open connection
$ch = curl_init();
$timeout=60;
//set the url and other options for curl
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); // Values: GET, POST, PUT, DELETE, PATCH, UPDATE
curl_setopt($ch, CURLOPT_POSTFIELDS, $domainsJSON);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
//execute post and return response data.
$result = curl_exec($ch);
//close curl connection
curl_close($ch);
// decode the json response
$dn = json_decode($result, true);
echo '<pre>'; print_r($dn); echo '</pre>';
Im trying to consume a WCF webservice using get or post with php , it is a great example, it works locally but I need to make it work remotelly.
The code is a great test example because it allows you to see both the get and post requests.
This is a model of the url (not the real one).
https://anyweb.com/anyservice.svc/GetShops
This is the error from the server
The exception message is 'Invalid value for 'encryptedTicket'
parameter.'
What should I do to solve it? It seems there is not to much written about this.
The code below
<?php
echo 'Call the service using GET <br>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://anyweb.com/anyservice.svc/GetShops".
"");
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print_r($result);
echo '<br>';
echo '<br>Call the service using POST <br>';
$transmitObject = array("fname" => "MASTER", "lname" => "POGI");
$jsonObject = json_encode($transmitObject);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://anyweb.com/anyservice.svc/GetShops");
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonObject);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
print_r($result);
?>
The value or maybe datatype you are posting for encryptedTicket is wrong
Read their docs and see what is expected to be received by their web service for that field
I am trying to initiate a refund using click bank api with below source code.
$ch = curl_init();
$qry_str="?type=rfnd&comment=API refund check&reason=7&refundType=FULL";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.clickbank.com/rest/1.3/tickets/N5GNE72J'.$qry_str);
curl_setopt($ch, CURLOPT_HEADER, true);
//curl_setopt($ch, CURLOPT_GET, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization:DEV-xxxxxxxxx:API-yyyyyyyyyyyy"));
$result = curl_exec($ch);
curl_close($ch);
print $result;
I have used below two url for reference:
https://api.clickbank.com/api/api_13_examples/api_example.php
https://api.clickbank.com/rest/1.3/tickets
After executing above code it shows a blank screen nothing is displyed, My error flag is set to 1 still no error shown.
After a long struggle found the solution. Use below code it worked for me.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
"https://api.clickbank.com/rest/1.3/tickets/627JE7CZ/?type=rfnd&comment=&reason=ticket.type.refund.7&refundType=FULL");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
/**
* ClickBank doesn't allow POST parameters to be sent in; however, for the CURL POST to work correctly, the
* CURL_POSTFIELDS option must be set, so we'll just set it to empty and put all our request parameters on the URL
*/
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/xml",
"Authorization:DEV-enter your dev key here:API-enter your clerk key here"
));
$result = curl_exec($ch);
curl_close($ch);
?>
I want to exceute this using php curl
[ ~ ] $ curl -u cbb8f088775cf209035729c0eb69b9f340a3b047:X https://subs.pinpayments.com/api/v4/meresheep/subscribers.xml
So far, I tried
// Query the user to pin payments for the details...
$curl_url = "https://subs.pinpayments.com/api/v4/rigid-test/subscribers/rigids-12345.xml";
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: -u cbb8f088775cf209035729c0eb69b9f340a3b047'));
// curl_setopt($data, CURLOPT_HTTPHEADER, array(
'Authorization: Basic ' . base64_encode('cbb8f088775cf209035729c0eb69b9f340a3b047')
));
//execute post
echo $result = curl_exec($ch);
echo curl_error($ch);
die('qqqqqqqqq');
curl_close($ch);
Mistakenly the variable used was wrong.
Here is the code again.
// Query the user to pin payments for the details...
$curl_url = "https://subs.pinpayments.com/api/v4/rigid-test/subscribers/12345.xml";
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $curl_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_USERPWD,"b59d75bbdead46741b3b6875fc4b50e698392d71:test4321");
//execute post
$result = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);