Why am I getting a HTTP 400 bad request error?

user1460815 picture user1460815 · Oct 13, 2012 · Viewed 14.6k times · Source
<?php
$url ="http://absolutesms.com/Sendsms.aspx?userid=userid&password=password&clientid=clientid&senderid=absolute&mobilenumber=919000024365&smsmessage=SingleMessage".$request;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
?>

After running this code I am getting HTTP Error 400. The request is badly formed. What should I do? I tried other url they are working fine the only problem is with this. If I copy this url in browser it's working but it's giving error 400 when I put it and run it in curl.

Answer

Jay Julian Payne picture Jay Julian Payne · Jul 14, 2013

I see this a lot. Usually fixed by running the request through urlencode().