0

I've been trying to setup a cURL call to a REST API for days (see my previous topics) and still it won't work...

Though, what I need is fairly simple:
I need make a call with the POST method to an url. This URL requires authentication (which, according to the documentation, I should pass by HTTP headers using the GET function). And on top of that, I need to set a body (<searchCriteriaSorting></searchCriteriaSortin) and I should use the Content-Type: application/xml and the Charset=UTF-8.

Nothing more, nothing less. According to the author of the API, it should be very simple. But me, nor my colleagues manage to build a solid connection to this API.

3
  • Haven't you asked that question already? Mar 23, 2012 at 15:20
  • Not really... I've asked questions related to this topic, but they didn't help me out. So I'm looking for a fresh start!
    – Michiel
    Mar 23, 2012 at 15:21
  • please provide the link to the documentation of the API.
    – Gordon
    Mar 23, 2012 at 15:27

1 Answer 1

6

To use authentication you can use the cURL option CURLOPT_USERPWD. To define that you'd like to use POST use cURL option CURLOPT_POST. To set the required headers you can use use cURL option CURLOPT_HTTPHEADER. Finally you have to set the body of the HTTP POST request be using cURL option CURLOPT_POSTFIELDS, whereby $xml is your XML content.

/* init cURL session */
$ch = curl_init();
...
/* set password */
curl_setopt($ch, CURLOPT_USERPWD, "loginname:passwort");
/* use method POST */
curl_setopt($ch, CURLOPT_POST, true);
/* set header 'Content-Type' */
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=UTF-8'));
/* set HTTP body */
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
...
/* exec cURL request */
curl_exec($ch);
curl_close($ch);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.