0

i am trying to use the CURL to get a respose back in a PHP web app..

curl -d "qid=QID&api_key=API_KEY&api_sig=API_SIG&time_stamp=TIMESTAMP" \
 http://api.1.com/v1.2/result/

I have all the variables as known - but how do i form and execute above in PHP to get the result into a $RESULTRESPONSE variable? I am expecting a response in xml format back.

I know of curl_init, curl_exec, but not sure how curl_setopt comes into play for this. Thanks.

1 Answer 1

9
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'YOU_URL_GOES_HERE');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
$YOUR_RETURN_EDCONTENT_GOES_HERE = curl_exec($ch);
curl_close($ch);

Not 100% sure what you mean, but this will store your information from the curl in the $YOUR_RETURN_EDCONTENT_GOES_HERE variable.

Sign up to request clarification or add additional context in comments.

3 Comments

In above API example: curl -d "qid=QID&api_key=API_KEY&api_sig=API_SIG&time_stamp=TIMESTAMP" \ api.1.com/v1.2/result
Is the CURLOPT_URL == api.1.com/v1.2/result/… ??
Replace 'YOUURLGOESHERE' with your url, yes. But I can't access that webpage. Are you sure it's correct?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.