如何将 content-type header 设置为空?

How to set the content-type header to nothing?

我想提出 POST 请求:http://NUXEO_SERVER/nuxeo/api/v1/upload/

没有要发送的数据,但是此网络服务需要一个 POST 方法。那么如何设置header的Content-type呢?

这是我的代码:

$nuxeoBatchId = file_get_contents('http://192.168.128.101/nuxeo/api/v1/upload/', false, stream_context_create([
                  'http' => [
                              'method' => 'POST',
                              'header'  => "Content-type: text/html",
                              'content' => http_build_query([]) // of form 'key1' => 'Hello world!', 'key2' => 'second value'
                            ]
                   ])
                 );
$response->setContent($nuxeoBatchId);
return $response;

根据https://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.2.1

Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource. If the media type remains unknown, the recipient SHOULD treat it as type "application/octet-stream".

我想如果你不知道媒体类型,你应该跳过 Content-Type 或设置为 application/octet-stream

如果没有要发送的负载,那么您根本不应该设置 Content-Type header 字段。