I am trying to build an application using Google Opensocial API.
But when i make a POST request with following CURL headers, i am getting 405 Method not allowed error :
CURLOPT_URL : http://www.orkut.com/social/rpc/
CURLOPT_POSTFIELDS : [{"method":"people.get","id":"self","params":{"userId":["#me"],"groupId":"#self","fields":["displayName","currentLocation","thumbnailUrl","gender","name"]}},{"method":"people.get","id":"friends","params":{"userId":["#me"],"groupId":"#friends","fields":["displayName","currentLocation","thumbnailUrl","gender","name"],"count":300}}]
CURLOPT_CUSTOMREQUEST : POST
CURLOPT_RETURNTRANSFER : true
CURLOPT_USERAGENT : osapi 1.0
CURLOPT_FOLLOWLOCATION : 1
CURLOPT_SSL_VERIFYPEER : false
CURLOPT_HEADER : true
CURLINFO_HEADER_OUT : true
CURLOPT_HTTPHEADER : Array
(
[0] => Authorization: OAuth oauth_body_hash="A3ZOHT4b3YMOzEfg+2j3v+N302E=", oauth_nonce="6ad533sdfsb9261ssdfsdf29af7d", oauth_version="1.0", oauth_timestamp="1318236734", oauth_consumer_key="www.mydomain.com", oauth_token="1%2FKhAasdfsd8YX2bfsdfsdf6MsdfsfsdfsdfJYyULWUog", oauth_signature_method="HMAC-SHA1", oauth_signature="osdf4pShOsdfsdf88nnpwsdfsdf9g%3D"
[1] => Content-Type: application/json
[2] => Content-Length: 0
[3] => User-Agent: osapi 1.0
)
Following is the CURL-POST response I am recieving :
["http_code"] => int(405)
["data"] => string(12614)
"HTTP/1.1 405 Method Not Allowed
Content-Type: text/html; charset=UTF-8
Content-Length: 12462
Date: Tue, 14 Jun 2011 08:07:58 GMT
Server: GFE/2.0
I asked about this issue on Google Codes forum and they told me to remove following line from CURL request as my website is hosted on hostgator.
CURLOPT_CUSTOMREQUEST : POST
I tried above thing but still i am getting 405 Method not allowed error. Kindly assist me further on this issue.
Do i need to modify my PHP-CURL code above to send POST request? If so, then please help me..
The Google Social specification has an example in which people.get is requested with GET, not via POST. Generally keep in mind that GET is for requesting information, while POST is for changing existing information.
Related
Request:
$headers = array( 'Content-Type:application/xml' );
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://example.com',
CURLOPT_POST => 1,
CURLOPT_HEADER => $headers,
CURLOPT_USERPWD=>'test:test',
CURLOPT_POSTFIELDS => $XMLData
));
$APIResponse = curl_exec($curl);
curl_close($curl);
And I get this response from an API
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: ----
X-AspNet-Version: -----
X-Powered-By: ASP.NET
Date: ---- GMT
Content-Length: 100
<?xml version="1.0" encoding="utf-8"?><response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.example.com"><ID>12345</ID></response>
I want to fetch ID from xml ID tag. How can I get that in my php code?
You're getting the HTTP header data included within your response from cURL, which is making it hard to extract the XML part.
However this is happening due to a simple misunderstanding - the CURLOPT_HEADER option doesn't do what you think it does.
That doesn't include your request headers in the request (as your code seems to be trying to do), instead it sets an option telling cURL whether or not the response headers should be included in the main output or not. If you set
CURLOPT_HEADER => 0
in your code, your problem should go away - then only the response body (in your case, just the XML) will included in the output from curl_exec.
In the meantime, if you need to set custom HTTP headers in your request, you can do it via the CURLOPT_HTTPHEADER option - a detailed example can be found here and in many other places online.
P.S. Admittedly these option names are not, in themselves, very clear about the difference between them, but the PHP manual does describe what they do in more detail.
I have integrate payfast payment gateway in our Laravel 5.1 website, it is working perfect on our development server but when we move site on live server it give error in ITN request step, here is the error which I am getting:
HTTP/1.1 500 Internal Server Error
Date: Wed, 09 Nov 2016 14:10:09 GMT
Server: Apache
Cache-Control: no-cache, private
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
When I am searching for solution I got below option to enable ITN request without CSRF token
protected $except = [
//
'/itn'
];
but this also not working, I put sample code folder on my website root folder and try to do payment and that will working.
Also when I try to write notify response in text file it print success in response to the file.
After debugging my code I found there is problem with the CURL post.
// Base settings
$curlOpts = array(
// Base options
CURLOPT_USERAGENT => USER_AGENT, // Set user agent
CURLOPT_RETURNTRANSFER => true, // Return output as string rather than outputting it
CURLOPT_HEADER => false, // Don't include header in output
CURLOPT_SSL_VERIFYHOST => true,
CURLOPT_SSL_VERIFYPEER => false,
// Standard settings
CURLOPT_URL => 'https://' . $pfHost . '/eng/query/validate',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $pfParamString,
);
curl_setopt_array($ch, $curlOpts);
// Execute CURL
$res = curl_exec($ch);
curl_close($ch);
Main issue occurs because of these two line code
CURLOPT_SSL_VERIFYHOST => true,
CURLOPT_SSL_VERIFYPEER => false,
I change its value and it start working
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_SSL_VERIFYPEER => true,
This will fix my problem and payfast working perfect after doing these changes.
Hi I want to integrate Paypal API in my Zend FW 1 application.
my code is
$this->setHeaders(
array(
'Authorization' => '<REMOVED>',
'content-type' => 'application/json',
)
);
$this->setMethod('POST');
$this->setParameterGet('payer_id', $company_id);
$this->setParameterGet('number', $cc_number);
$this->setParameterGet('type', $type);
$this->setParameterGet('exp_month', $exp_month);
$this->setParameterGet('exp_year', $exp_year);
$this->setParameterGet('payer_id', $company_id);
$this->setParameterGet('first_name', $first_name);
$this->setParameterGet('last_name', $last_name);
return $this->request();
Debug show this
string(364) "POST /v1/vault/credit-card?number=4417119669820331&type=visa&exp_month=05&exp_year=2019&first_name=john&last_name=travolta HTTP/1.1
Host: api.sandbox.paypal.com
Connection: close
Accept-encoding: gzip, deflate
User-Agent: Zend_Http_Client
Authorization: Bearer <REMOVED>
content-type: application/json
Content-Length: 0
But when I run i get this error from PayPal
"Method Not Allowed"
Where is problem? I do POST and he said that is not allowed? Allowed method are POST, GET, HEAD, OPTIONS. Where i making mistakes?
I want to store credit card
Paypal API requires strict usage of correct requests.
This includes a valid Accept: application/json header and valid
json content being send. You can not set content-type without sending any content
In this case Zend_HTTP_Client's rawData() should be used.
I just want to send a POST request to YouTube's server to upload a video directly to YouTube via OAuth.
I have an access token and developer key - how could I send a POST request from PHP to YouTube's gdata server?
The POST request I want to send is found here: Sending an Upload API Request
POST /feeds/api/users/default/uploads HTTP/1.1
Host: uploads.gdata.youtube.com
Authorization: Bearer ACCESS_TOKEN
GData-Version: 2
X-GData-Key: key=DEVELOPER_KEY
Slug: VIDEO_FILENAME
Content-Type: multipart/related; boundary="BOUNDARY_STRING"
Content-Length: CONTENT_LENGTH
Connection: close
--<boundary_string>
Content-Type: application/atom+xml; charset=UTF-8
API_XML_request
--BOUNDARY_STRING
Content-Type: VIDEO_CONTENT_TYPE
Content-Transfer-Encoding: binary
<Binary File Data>
--BOUNDARY_STRING--
I tried the below function, and a lot more like it, but it can't send the XML part of the above mentioned POST request.
if (!function_exists('send_post_request'))
{
function send_post_request($url, $data)
{
$context = stream_context_create(array('http' => array('method' => 'POST',
'content' => http_build_query($data))));
$result = file_get_contents($url, FALSE, $context);
return $result;
}
}
I also tried cURL!
I'm having issues connecting to an ASP.Net web service using PHP.
The web service is known to be operational, since it's returning data when we connect using Javascript from the same domain, but when I attempt to connect using PHP I receive the following error:
HTTP/1.1 500 Internal Server Error Content-Type: application/json; charset=utf-8 Server: Microsoft-IIS/7.5 jsonerror: true X-Powered-By: ASP.NET Date: Tue, 17 May 2011 03:40:17 GMT Connection: close Content-Length: 819
{"Message":"Invalid JSON primitive: birthday.","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\
[etc]
The Content-Type is set to "application/json; charset=utf-8" in PHP, and we are trying to send a parameter called "birthday" using the following POST data in PHP:
$post_data = array(
'birthday' => 'none'
);
I think the ASP web service is not able to parse the 'birthday' parameter for some reason, but I'm not sure why.
Do I need to explicitly encode the POST data as JSON from PHP before calling the web service?
Thanks.
May be this web service takes the post data in Json format. If it is then you should use
$post_data = array( 'birthday' => 'none' );
$jsonData = json_encode ($post_data );
for details json_encode