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

前端 未结 6 2041
野趣味
野趣味 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:53

    You could create a stream context with the HTTP version set to 1.0 and use that context with file_get_contents:

    $options = array(
        'http' => array(
            'protocol_version' => '1.0',
            'method' => 'GET'
        )
    );
    $context = stream_context_create($options);
    $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, false, $context);
    

    By the way: Don’t forget to escape your URI argument values properly with urlencode.

提交回复
热议问题