开发者

How to resolve HTTP/1.1 400 Bad Request

开发者 https://www.devze.com 2023-04-12 07:06 出处:网络
All, I am accessing a web-page through command prompt using simple_html_dom in php as $page = file_get_html($url, false, $context);

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 re开发者_如何学运维sponse. 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.


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); 


If you're generating that url yourself, you'll have to url_encode the query values:

$url = 'http://example.com/xyz.html?s=' . urlencode('some text');

which'll give you

http://example.com/xyz.html?s=some+text
                                  ^---spaces must be + in urls.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号