Re[2]: [PHP] XML API, libcurl, POST Help Needed



Hi Jochem,

Thanks very much for your help. I now have the application working. Just for
anyone elses interest here are a few comments.


$length = "Content-Length: 502";

JM> The way I see it your Content-Length is wrong - the
JM> length of your request in this instance would 380 bytes,
JM> based on the length of $xmlstr. but that's probably not right
JM> either.

JM> I imagine you need to set Content-Length dynamically,
JM> assuming curl doesn't do that for you ...

Yes curl does it for you I have discovered. So I removed this Content-Length and
found that it is now dynamically generated.

JM> as a side note: why bother setting all these vars then stricking
JM> them in an array - why not just stick the strings directly in the array?
JM> additionally if you don't need to use double quotes (for variable
JM> interpolation) single quotes are [marginally] faster [in theory] because
JM> no variable interpolation is attempted on them.

Because I was being a bit lazy and wanted to see more of what was going on. Of
course you are right and I have now cleaned up my code as you have suggested.

$a_encoding = "Accept-Encoding: gzip";

JM> not related to your current issue, but are your really accepting
JM> a gzip'ed reply? this might cause you headaches once you have the
JM> current problem solved.

Yeah this gzip is a real pain. The API specifies either a gzipped or a
compressed data transfer. Some of the returns from the server, in Germany, can
be quite large so I guess the developers wanted to save some bandwidth by
compressing the data. I have just discovered that if I leave the
Accept-Encoding: gzip out all together then the whole process works with the
data returned in plain uncompressed text :-)


curl_setopt($curl, CURLOPT_POSTFIELDS, urlencode($xmlstr));

JM> I am guessing that the urlencoded $xmlstr should be given a POST parameter name,
JM> what that name is I don't know but the previous line should look something like
JM> this (*I think*):

JM> curl_setopt($curl, CURLOPT_POSTFIELDS, array('xml' => urlencode($xmlstr)));

This was where I had suspected I was having trouble. What I did find was that
the whole thing now works just by removing the urlencode all together. It
appears that the Content-Length was the problem all along and once that was
fixed and the urlencode was removed everything was fine.

JM> you might consider point the curl request to a script you control,
JM> so that you can see exactly what the request is sending.

JM> e.g. $url = 'http://yourdomain.tld/your-curl-request-test.php';

JM> ... and have your-curl-request-test.php write all it's recieved headers, etc
JM> to a log file.

Probably a good idea for debugging.

Thanks for your help.



Regards,
Richard Luckhurst
Product Development
Exodus Systems - Sydney, Australia.
rluckhurst@xxxxxxxxxxxxx
.



Relevant Pages

  • Re: PHP Passing Variables Between Pages and Security
    ... it as a parameter in the next request (again using CURL). ... Command-line CURL can and will save cookies (specifically the session ... the first tests I ran didn't work at ...
    (comp.lang.php)
  • Re: PHP Passing Variables Between Pages and Security
    ... it as a parameter in the next request (again using CURL). ... Command-line CURL can and will save cookies (specifically the session ... What exactly are you trying to protect against here? ...
    (comp.lang.php)
  • Re: Problem relaying uploads
    ... print reverse($_); # reverse the line, ... Your curl command is totally wrong. ... and issue the request to the server. ...
    (comp.lang.perl.misc)
  • So let me get this straight about CURL
    ... In order to make an http request with PHP, ... In order to install CURL I have to upgrade my openssl rpm, ... To make php make an https request, you either have to do the entire ...
    (comp.lang.php)
  • Re: Help With CURL And GET Forms
    ... After the form submission the url is a mess and pretty customized ... How would I deal with this in curl? ... // urlencode all values ... Then just use the baseurl in CURL without POST-options. ...
    (comp.lang.php)