curl-and-php
RE: Odd cURL problem....
Date: Sat, 23 Mar 2002 01:17:54 -0500
Chris-
The code you included is already set up to post. How do you know it doesn't
post correctly? I.e. what response do you get? You have to get some response
from the server.
Try changing: curl_setopt($ch, CURLOPT_HEADER, 0);
to: curl_setopt($ch, CURLOPT_HEADER, 1);
Then try your script again and take a look at the response header. That will
tell you what is happening at this stage. For example, the remote site could
be using redirects as part of establishing a session. If you don't follow
the redirects, all you are getting is cookie headers.
If so, you need to set curl to handle the cookies and follow redirects:
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$cookiefile = '/your_file_path/cookies.txt';
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookiefile);
Let me know how it goes.
-J.
-----Original Message-----
From: curl-and-php-admin_at_lists.sourceforge.net
[mailto:curl-and-php-admin_at_lists.sourceforge.net]On Behalf Of Chris
Cornutt
Sent: Friday, March 22, 2002 6:06 PM
To: curl-and-php_at_lists.sourceforge.net
Subject: Odd cURL problem....
Alright, so here's my code right now:
-------------------------------------------------------------
function newSend($info){
echo "<b>Using curl socket on test site...</b><br>";
echo "<b>Sent XML:</b> ".htmlspecialchars($info)."<Br>"; flush();
$ch = curl_init();
$DeveloperName="foo";
$ApplicationName="test";
$SessionCertificate="bar";
$cert="X-EBAY-API-SESSION-CERTIFICATE:".$DeveloperName.";".$ApplicationName.
";".$SessionCertificate;
$compat="X-EBAY-API-COMPATIBILITY-LEVEL:237";
$headers[]=$cert."\r\n\r\n".$compat."\r\n\r\n";
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_URL, "https://test.server.com/aw-cgi/API.dll?");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $info);
curl_setopt($ch, CURLOPT_POST, 1);
$test=curl_exec($ch);
echo "Info:".$test."<p>";
if(curl_error($ch)){
echo curl_error($ch);
}
curl_close ($ch);
return $test;
}
-------------------------------------------------------------
Now, this works all well and good, but it's not the right way to do
it.....to do it right, I have to POST the XML ($info) that I want to send to
that same URL - something like:
curl_setopt($ch, CURLOPT_URL, "https://test.server.com/aw-cgi/API.dll");
curl_setopt($ch, CURLOPT_POSTFIELDS, $info);
But that doesn't POST the info correctly and doesn't give me any response
from the server....
Any ideas on how I could make this thing work?
-chris
developer_at_catalog.com
Received on 2002-03-23