Why did I get a 400 Bad Request when getting a page with PHP Curl?
<p>I was trying to access a page using curl. I could access it perfectly using the browser and using "static" strings as the URL, like:</p>

<pre><code>$url = "http://www.example.com/?q=1234"
</code></pre>

<p>But when I tried to access the page using a variable in the URL string like:</p>

<pre><code>$url = "http://www.example.com/?q=$param"
</code></pre>

<p>I got a 400 error code. I checked out on the web and found some comments here in <a href="http://stackoverflow.com/questions/1466681/400-bad-request-when-getting-a-page-with-php-curl">this</a> stackoverflow thread:</p>

<p>Then, just for curiosity I did the following: </p>

<pre><code>$url = "http://www.example.com/?q=" . trim($param);
</code></pre>

<p>and it worked! And no, <code>$param</code> did NOT contain any spaces.</p>

<p>To me, it seems that it can be some encoding error, but I really can't find an explanation for it. Does anyone here in stackoverflow know what it can possibly be?</p>

<p>Thanks in advance :)</p>
