HTTP POST with a JSON Body
An HTTP POST containing a JSON body looks something like this:
POST /v2/checkout/orders HTTP/1.1 Host: example.com Accept: */* Accept-Encoding: gzip Content-Type: application/json Content-Length: 82 Request-Id: 7b92603e-77ed-4896-8e78-5dea2050476a Authorization: Bearer Access-Token {"reference_id":"REFID-000-1001","amount":{"currency_code":"CAD","value":"10.00"}}
About the HTTP POST
- The 1st line is the HTTP start line. It contains the HTTP verb ("POST"), followed by the path part of the URL, and finally the HTTP protocol version.
- Following the start line, we have standard MIME. HTTP requests and responses are MIME, just like emails are MIME. A MIME message is composed of a header followed by a blank line, followed by the MIME body. In this case, the MIME body will be the JSON document.
- The Content-Type header describes the type of content in the MIME body. For JSON it is typically "application/json" or (less common) "text/json".
- Content-Length indicates the exact number of bytes in the body of the HTTP request (i.e. the length of the content that follows the blank line). Chilkat always automatically computes and adds the Content-Length header for you.
- The Host header is the domain part of the URL. In the above example, the URL would be "https://example.com/v2/checkout/orders". Chilkat always automatically adds the Host header.
- The Accept and Accept-Encoding headers are automatically added by Chilkat, but can be changed by your app or suppressed. They tell the server information about what kinds of responses are acceptable.
- Request-Id is an example of a custom header required by a particular server. Your application can add custom headers.
- Authorization is a standard header used for authentication. In this example, we're sending an OAuth2 access token.
- You can generate source code from a raw HTTP request using Chilkat's online tool at https://tools.chilkat.io/httpRequestToCode.
CURL
A CURL statement to send the above HTTP request is shown here. You can generate source code from a CURL statement using Chilkat's online tool at https://tools.chilkat.io/curlHttp
curl -v -X POST https://example.com/v2/checkout/orders \ -H "Accept: */*" \ -H "Accept-Encoding: gzip" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer Access-Token" \ -H "Request-Id: 7b92603e-77ed-4896-8e78-5dea2050476a" \ -d '{ "reference_id": "REFID-000-1001", "amount": { "currency_code": "CAD", "value": "10.00" } }'
Chilkat Examples Implementing the Above POST
Android™ HTTP POST with JSON Body
Classic ASP HTTP POST with JSON Body
AutoIt HTTP POST with JSON Body
C HTTP POST with JSON Body
Chilkat2-Python HTTP POST with JSON Body
C++ HTTP POST with JSON Body
C# HTTP POST with JSON Body
DataFlex HTTP POST with JSON Body
Delphi ActiveX HTTP POST with JSON Body
Delphi DLL HTTP POST with JSON Body
.NET Core C# HTTP POST with JSON Body
Visual FoxPro HTTP POST with JSON Body
Go HTTP POST with JSON Body
Java HTTP POST with JSON Body
Mono C# HTTP POST with JSON Body
Node.js HTTP POST with JSON Body
Objective-C HTTP POST with JSON Body
Perl HTTP POST with JSON Body
PHP ActiveX HTTP POST with JSON Body
PHP Extension HTTP POST with JSON Body
PowerBuilder HTTP POST with JSON Body
PowerShell HTTP POST with JSON Body
PureBasic HTTP POST with JSON Body
CkPython HTTP POST with JSON Body
Ruby HTTP POST with JSON Body
SQL Server HTTP POST with JSON Body
Swift HTTP POST with JSON Body
Tcl HTTP POST with JSON Body
Unicode C HTTP POST with JSON Body
Unicode C++ HTTP POST with JSON Body
Visual Basic 6.0 HTTP POST with JSON Body
VB.NET HTTP POST with JSON Body
VBScript HTTP POST with JSON Body
Xojo Plugin HTTP POST with JSON Body