Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP CURL GET request returns 500 where bash curl succeeds
    primarykey
    data
    text
    <p>I'm attempting to use PHP's CURL to make a GET request to a server and am having some difficulties doing so. When I make the request through PHP I am returned a 500 error from the external server. However, if I make the request using the bash curl, or visit the URL in a browser it succeeds.</p> <p>I've stripped the PHP down to the bare essentials:</p> <pre><code>$url = 'http://example.com:8080/path/to/service?cmd=my_command&amp;arg=example2.com'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); print_r(curl_getinfo($ch)); curl_close($ch); </code></pre> <p>As stated this returns a 500 error from example.com. However, if I do the following:</p> <pre><code>[me@host ~] curl "http://example.com:8080/path/to/service?cmd=my_command&amp;arg=example2.com" </code></pre> <p>I am returned the expected XML document.</p> <p>What gives? It's got to be something with the encoding of the URL, as if I strip the <code>$url</code> var down to just <code>http://example.com:8080</code> the PHP CURL request now responds with 200. I've tried replacing the <code>&amp;</code> with <code>%26</code> - that didn't work (nor would I expect it to, as <code>&amp;</code> is valid in the URL there). I've tried doing what the answer for <a href="https://stackoverflow.com/questions/10230774/php-curl-sending-vars-using-get-wierd-results">php curl sending vars using GET wierd results</a> suggested, but that didn't help either.</p> <p>What am I missing here? I'm sure that it's something absurdly simple, but it's escaping me.</p> <p>Thanks!</p> <p>EDIT: I've just attempted doing this in Python - just to see what happened - and it works fine there:</p> <pre><code>import urllib2 r = urllib2.urlopen(theURL) r.read() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload