0

I am getting an invalid content type error with a POST request to an ApiGility API.

array (size=4) 'type' => string 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html' (length=54)
'title' => string 'Unsupported Media Type' (length=22) 'status' => int 415 'detail' => string 'Invalid content-type specified' (length=30)

So this is telling me that I am sending in the incorrect content type.

Here is my code:

        $client = new Client(); //Zend/Http/Client
        $client->setUri('http://example.com/api/transfer');
        $client->setMethod('POST');
        $client->setOptions(
            [
                'maxredirects' => 0,
                'timeout' => 60
            ]
        );

        $client->setHeaders(['Accept' => 'application/json', 'Authorization' => 'Bearer 123453c112345c25256ff2dacb8ab212345ace91' ]);

        $client->setParameterPost(
            [
                'total' => 1,
                'code' => '0f08c43582f14686aabec4610b332629'
            ]
        );


        try {
            $response = $client->send();
        } catch (\Exception $e) {
            throw new \Exception($e);

        }

        $responseObject = json_decode($response->getBody());

        $hydrator = new \Zend\Stdlib\Hydrator\ObjectProperty;

        $result = $hydrator->extract($responseObject);

        die(var_dump($result));

What I cant work out from the manual: http://framework.zend.com/manual/current/en/modules/zend.http.client.html or the actual Client code, is where to set the content type?

HappyCoder
  • 5,985
  • 6
  • 42
  • 73

1 Answers1

1

'Content-Type' should simply be another entry in the array you use for $client->setHeaders(). The Client should default to 'multipart/form-data' though.

Can you do a var_dump() of $client->getRequest()->getHeaders()?

Wilt
  • 41,477
  • 12
  • 152
  • 203
lsklyut
  • 366
  • 3
  • 7