Set HTTP Request "Content-Type" Set HTTP Request "Content-Type" curl curl

Set HTTP Request "Content-Type"


I believe the headers must be a plain array whose elements are full key:value headers, not an associative array:

$headers = array();$headers[] = 'Accept: application/xml';$headers[] = 'Content-Type: application/xml';curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

This is specified in the curl_setopt() documentation.


You set an accept type for your request (and use Michael's answer for that, you should count his answer as answering the direct question, because it does). That doesn't mandate that the server resonds with that content type.

If the other end of the request is a static file, you have to make sure your web server sends that file with a MIME type of application/xml. If it ends with .xml, then both Apache and IIS will already do this. If it's something else that is a non-standard file extension, but you want it to be sent as application/xml, then you'll have to get the server manager to set the httpd.conf or .htaccess to add the mime type for the file. In IIS you use the GUI admin tools to do the same thing, adding a mime type for the file extension as application/xml.

If the other end of the request is a server side scripting language such as PHP, Perl, Python, ColdFusion, ASP, ASP.net, etc etc then you need to use the appropriate method/function in that language for the script being called to emit the content type header and set it to application/xml.

Update: You say in comments you're using WizTools to emit a request that does get a return of application/xml. If you want to clone that environment, then send ALL the headers it's sending in your curl request. One guess is that user agent might be in play.