How to resolve HTTP/1.1 400 Bad Request

httpwebrequestsimple-html-dom

All,

I am accessing a web-page through command prompt using simple_html_dom in php as

  $page = file_get_html($url, false, $context); 

where $url is the web-URL.
If you URL is like http://abc.com/xyz.html?s="sometext"
Then i am getting proper response.
But I am getting HTTP/1.1 400 Bad Request if the URL has white space in the get parameter like http://abc.com/xyz.html?s="some text".

Can anyone please help me how to resolve this issue.

Thanks in advance.

Best Answer

You need to encode the parameter:

$text = urlencode('some text');
$url = "http://abc.com/xyz.html?s=$text";
$page = file_get_html($url, false, $context);