HTTP 请求失败!HTTP/1.1 505 HTTP 版本不支持错误 [英] HTTP request failed! HTTP/1.1 505 HTTP Version Not Supported error

查看:61
本文介绍了HTTP 请求失败!HTTP/1.1 505 HTTP 版本不支持错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 file_get_contents() 从服务器获取响应,但遇到了此错误.有人能告诉我是什么原因以及如何解决吗?代码部分是:

I'm trying to use file_get_contents() to get the response from a server and this error was encountered. Could someone tell me what is the reason and how to fix it? The portion of the code is:

$api = "http://smpp5.routesms.com:8080/bulksms/sendsms?username=$username&password=$password&source=$source&destination=$destin&dlr=$dlr&type=$type&message=$message";
$resp = file_get_contents($api);

当我在浏览器中粘贴 url 时,服务器正确响应.我了解到这是由于服务器拒绝客户端的 HTTP 版本造成的,但我不知道为什么会在我的情况下发生这种情况.

The server responded correctly while I pasted the url in the browser. I learned that this is caused by the server rejecting the client's HTTP version, but I have no idea why that is happening in my case.

非常感谢任何帮助.提前致谢

Any help is much appreciated. Thanks in advance

推荐答案

我发现了问题,这是一个简单的编码错误——缺少 url 编码.

I found the problem, and it was a simple coding error -- missing url encoding.

我一开始没注意到的原因是因为在我做一些编辑之前代码是好的,而我在调用服务器之前错过了urlencode()函数,导致网址中的一个空格.

The reason I didn't notice it at first was because the code was ok before I did some editing, and I'd missed out the urlencode() function before calling the server, which caused a space in the url.

这似乎是大多数人出现此错误的原因.因此,如果您遇到这种情况,请在用作 URL 参数的值中可能包含空格的所有变量上使用 urlencode().因此,在我的问题中,固定代码将如下所示:

This does seem to be the reason this error occurs for most people. So if you encounter this, use urlencode() on all variables which may contain white space in it's value used as URL parameters. So in the case in my question the fixed code will look like:

$api = "http://smpp5.routesms.com:8080/bulksms/sendsms?username=$username&password=$password&source=$source&destination=$destin&dlr=$dlr&type=$type&message=" . urlencode($message);
$resp = file_get_contents($api);

另外,感谢您的时间和回复,这些都是信息性的.

Also, thanks for all of your time and responses, those were informational.

这篇关于HTTP 请求失败!HTTP/1.1 505 HTTP 版本不支持错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆