JavaScript/AJAX code for Curl POST XML Example
This JavaScript/AJAX code snippet was generated automatically for the Curl POST XML example.<< Back to the Curl POST XML example
What is Curl?
Curl is a popular command-line tool that allows you to send requests to the server, upload files, and submit web forms. Curl supports over 25+ protocols, including HTTP, HTTPS, SFTP, FTP, and has built-in support for web forms, SSL, user authentication, and HTTP cookies. Curl works on Linux, Mac, Windows.
What is the correct MIME type for XML data?
There are two registered MIME types for XML data: application/xml and text/xml. Use the application/xml when making requests to API endpoints (XML data is not readable by users) and use text/xml when users can view XML data. However, since the introduction of RFC 7303, they should be considered the same in all respects except for the name.
Why do I need to specify Content-Type when posting XML with Curl?
If you are posting XML data using Curl, you must explicitly specify the data type in the body of the POST request message. Otherwise, Curl will pass the application/x-www-form-urlencoded content type to the server for your data. Therefore, when you submit XML (or any other type of data), you need to explicitly specify the data type using the -H "Content-Type: application/xml" command-line argument.
Why do I need to pass the Accept header when requesting XML using Curl?
If your Curl client expects XML due to a submitted request, it must also send an Accept: application/xml request header to the server. Without this header, the server may return data in a different format.
The server informs the client that it has returned XML data with the Content-Type: application/xml response header.
Curl POST XML Request Example
Example of sending XML data to the ReqBin echo URL.