Hi, make sure you urlencode everything that is sent on the url, or as postvars. $d2 =urlencode($d2); and so on then curl_setopt($ch, CURLOPT_URL, $server); curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
don't use the $testrequest, cause it has un-urlenoded values I think that should do the trick. Merijn van den Kroonenberg e-factory bv Tel.: +31 (0)475 - 340 975 Fax: +31 (0)475 - 320 351 Web: www.e-factory.nl ----- Original Message ----- From: "Joshua Alexander" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, August 28, 2002 6:13 AM Subject: [PHP] Curl request works on command line but not in script > Hi folks, > > I'm trying to send an XML request to a server to get its response > back... I can get it to work on the command line (with passthru) but > not with libcurl. I'm using libcurl 7.9.2 which may actually be > different from the curl on the command line... the latter came with > OS X, the former came from entropy.ch with the PHP package I > installed. Of course my host is using 7.9.4 and the script doesn't > work there either. > > I've tried it with both GET and POST... here are some setup variables. > > $testrequest = "$server?API=Rate&XML=<RateRequest USERID=\"$userid\" > PASSWORD=\"$password\"><Package > ID=\"0\"><Service>EXPRESS</Service><ZipOrigination>20770</ZipOrigination><Zi pDestination>20852</ZipDestination><Pounds>10</Pounds><Ounces>0</Ounces><Con tainer>None</Container><Size>REGULAR</Size><Machinable></Machinable></Packag e></RateRequest>"; > > $post['API']="Rate\n"; > $post['XML']= "'<RateRequest USERID=\"$userid\" > PASSWORD=\"$password\"><Package > ID=\"0\"><Service>EXPRESS</Service><ZipOrigination>20770</ZipOrigination><Zi pDestination>20852</ZipDestination><Pounds>10</Pounds><Ounces>0</Ounces><Con tainer>None</Container><Size>REGULAR</Size><Machinable></Machinable></Packag e></RateRequest>'\n"; > > # (I've tried it with the 's and without, with the \n's and without) > > $d1 = "API=Rate"; > $d2 = "XML='<RateRequest USERID=\"$userid\" > PASSWORD=\"$password\"><Package > ID=\"0\"><Service>EXPRESS</Service><ZipOrigination>20770</ZipOrigination><Zi pDestination>20852</ZipDestination><Pounds>10</Pounds><Ounces>0</Ounces><Con tainer>None</Container><Size>REGULAR</Size><Machinable></Machinable></Packag e></RateRequest>'"; > > $ch = curl_init(); > > # doesn't work, returns Error 400 > curl_setopt($ch, CURLOPT_URL, $testrequest); > > # also doesn't work, returns BAD REQUEST > curl_setopt($ch, CURLOPT_URL, $server); > curl_setopt($ch,CURLOPT_POSTFIELDS,$post); > > # what DOES work > passthru("curl -d " . $d1 . " -d " . $d2 . " $server"); > > > Any ideas? > > -Josh > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php