duandeng2011 2019-08-06 11:41
浏览 358
已采纳

PHP POST请求提出HTTP / 1.0而不是HTTP1.1

I am new to PHP. I am trying to make a HTTPS POST request from PHP to an external server. Based on the posts on the Internet I have the following code:

// Create POST data.
$post_data = array(
    'roomId' => $space_token,
    'text' => $message
);

$output .= json_encode($post_data);

// Creating context
$context = stream_context_create(array(
    'http' => array(
        'method' => 'POST',
        'header' => "Authorization: Bearer {$api_access_token}
".
              "Content-Type: application/json
",
        'content' => json_encode($post_data)
    )
));

$response = fopen($api_url, 'r', false, $context);

However, the request is made with HTTP/1.0 instead of HTTP/1.1, and the server that i am trying to reach returns 502 Bad Gateway response when it receives HTTP/1.0 requests.

PHP Version: 5.4.16

HTTPD Version: Apache/2.4.6 (CentOS)

Not sure what I am doing wrong.

  • 写回答

1条回答 默认 最新

  • duanlei7101 2019-08-06 11:45
    关注

    You need insert to header 'protocol_version' => 1.1

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?