pheromix
pheromix

Reputation: 19287

How to set the content-type header to nothing?

I want to make a POST request : http://NUXEO_SERVER/nuxeo/api/v1/upload/

There is no data to send , but this webservice needs a POST method. So how to set the Content-type of the header ?

This is my code :

$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;

Upvotes: 0

Views: 1053

Answers (2)

Julian Reschke
Julian Reschke

Reputation: 42017

If there's no payload to send, then you shouldn't set a Content-Type header field at all.

Upvotes: 0

Urmat Zhenaliev
Urmat Zhenaliev

Reputation: 1547

According to 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".

I think if you don't know media type, you should just skip Content-Type or set to application/octet-stream

Upvotes: 1

Related Questions