http - Content Type not being set in cURL in PHP -
I am sending a request to use an API (Xero, to be specific) to cURL, but I Clearly sending the empty requests I checked the cURL information and it seems that I do not have any content-type set, even if I'm setting it up in code.
Here's my code:
$ content = $ this- & gt; GetContent (); $ Header = ["content-type: app / x-www-form-urlencoded", "content-length:". Strlen ($ content), "Connection: Off"]; $ Ch = curl_init (); Curl_setopt ($ c, CURLOPT_URL, $ this- & gt; getUrl ()); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, 1); Curl_setopt ($ CH, CURLOPT_TIMEOUT, 10); Curl_setopt ($ CH, CURLOPT_HTTPHEADER, $ headers); Curl_setopt ($ CH, CURLOPT_HEADER, true); Curl_setopt ($ ch, CURLOPT_POST, true); Curl_setopt ($ CH, CURLOPT_POSTFIELDS, $ content); D ($ header, curl_gateInfo ($ CH)); D () AA is a "dump and exit" function, and it outputs it:
array (3 ) {[0] = & gt; String (47) "content-type: app / x-www-form-urlencoded" [1] => String (20) "Content-Length: 1003" [2] = & gt; String (17) "Connection: Close"} array (26) {'url' = & gt; String (41) "https://api.xero.com/api.xro/2.0/Invoices" 'content_type' = & gt; Zero 'http_code' = & gt; Int (0) 'header_size' => Int (0) 'request_size' = & gt; Int (0) 'filetime' = & gt; Int (0) 'ssl_verify_result' = & gt; Int (0) 'redirect_count' = & gt; Int (0) 'total_time' = & gt; Double (0) 'minimize_time' = & gt; Double (0) 'connect_time' = & gt; Double (0) 'pretransfer_time' = & gt; Double (0) 'size_upload' = & gt; Double (0) 'size_download' = & gt; Double (0) 'speed_download' = & gt; Double (0) 'speed_upload' = & gt; Double (0) 'download_content_length' = & gt; Double (-1) 'upload_content_length' = & gt; Double (-1) 'starttransfer_time' = & gt; Double (0) 'redirect_time' = & gt; Double (0) 'certificate' = & gt; Array (0) {} 'primary_ip' = & gt; String (0) "'Primary_port' = & gt; Int (0) 'local_ip' = & gt; String (0)" 'local_port' = & gt; Int (0) 'redirect_url' = & gt; String (0) ""} As far as I think I'm setting the header correctly (continuously spelled and I have not set them multiple times). What am i doing
first curl_error function
because your URL < Code> https . Therefore, the SSL verification process is followed.
Informal correction:
curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, incorrect);
Formal correction:
curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, true); Curl_setopt ($ CH, CURLOPT_SSL_VERIFYHOST, 2); Curl_setopt ($ ch, CURLOPT_CAINFO, getcwd (). "/CAcerts/your_certificate.crt");
Where's the certificate?
- Browse URLs in the Firefox browser
-
Click on the lock pad on the left side of the address bar
-
Then More info Click
-
Now View certificate button
-
In the pop-up that you open, click the tab Details tab (shortcut ALT + D ) You will see two tabs in
-
Then click the Export button and save the certificate
curl_setopt ($ CH, CURLOPT_CAINFO, getcwd (). "/
< Li> Kaiser / your_script.crt ")
Comments
Post a Comment