1

I'm trying to do a cURL in PHP to an API that has a custom Content-Type response type option called "application/qhal+json". It returns a sort of JSON that's abstracted a bit for custom use.

What I'm using:

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CERTINFO, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: applcation/qhal+json'));

$result = curl_exec($ch);

However the response is always coming back as 'application/json' content type. Is it not possible to specify a custom content-type? Does anyone have any ideas on why the response isn't being returned in the correct format?

1 Answer 1

1

Please try the GET-request with an Accept Header:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/hal+json'));


The Accept header is used by HTTP clients to tell the server what content types they'll accept. The server will then send back a response, which will include a Content-Type header telling the client what the content type of the returned content actually is.

HTTP requests can also contain Content-Type headers. This header indicates which type of content is send to the server by a POST or PUT request.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.