HTTP request failed! HTTP/1.1 505 HTTP Version Not Supported error

前端 未结 6 2052
野趣味
野趣味 2020-12-07 01:27

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

6条回答
  •  难免孤独
    2020-12-07 01:37

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

    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.

    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.

提交回复
热议问题