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

查看:4435
本文介绍了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);

当我在浏览器中粘贴网址时,服务器响应正确。
我知道这是由服务器拒绝客户端的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

推荐答案

我发现了问题,这是一个简单的编码错误 - 缺少网址编码。

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

我最初没有注意到的原因是因为代码在我做一些编辑之前确定,我错过了 urlencode ()函数在调用服务器之前,这导致在URL中的空间。

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.

这似乎是这个错误的原因发生于大多数人。所以,如果你遇到这个,使用 urlencode()在所有可能包含空格的变量的值作为URL参数。所以在我的问题的情况下,固定的代码将看起来像:

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天全站免登陆