Set HTTP Request “Content-Type”

后端 未结 2 2007
傲寒
傲寒 2021-01-12 01:58

How do you set the content type of an HTTP Request?

I\'ve tried this:

$headers[\'Accept\'] = \'application/xml\';
$headers[\'Content-Type\'] = \'appl         


        
2条回答
  •  渐次进展
    2021-01-12 02:34

    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.

提交回复
热议问题