{"title":"HttpClient.Post(Text, HttpContent, var HttpResponseMessage) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/httpclient/httpclient-post-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/httpclient/httpclient-post-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/httpclient/httpclient-post-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Sends a POST request to the specified URI as an asynchronous operation.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"HttpClient.Post(Text, HttpContent, var HttpResponseMessage) Method","slug":"httpclientposttext-httpcontent-var-httpresponsemessage-method","at":0,"chars":13320},{"level":2,"title":"Syntax","slug":"syntax","at":201,"chars":115},{"level":2,"title":"Parameters","slug":"parameters","at":316,"chars":382},{"level":2,"title":"Return Value","slug":"return-value","at":698,"chars":299},{"level":2,"title":"Ways that HttpClient.Post calls can fail","slug":"ways-that-httpclientpost-calls-can-fail","at":997,"chars":1136},{"level":2,"title":"Example (HTTP POST)","slug":"example-http-post","at":2133,"chars":2021},{"level":2,"title":"Example (How to upload a file using multipart/form-data)","slug":"example-how-to-upload-a-file-using-multipartform-data","at":4154,"chars":5243},{"level":3,"title":"Example (How to upload a text file using multipart/form-data)","slug":"example-how-to-upload-a-text-file-using-multipartform-data","at":4968,"chars":1613},{"level":3,"title":"Example (How to upload a binary file using multipart/form-data)","slug":"example-how-to-upload-a-binary-file-using-multipartform-data","at":6581,"chars":2411},{"level":3,"title":"Example (How to upload large files using multipart/form-data)","slug":"example-how-to-upload-large-files-using-multipartform-data","at":8992,"chars":405},{"level":2,"title":"Content headers","slug":"content-headers","at":9397,"chars":2031},{"level":2,"title":"Supported HTTP methods","slug":"supported-http-methods","at":11428,"chars":1379},{"level":2,"title":"Contributors","slug":"contributors","at":12807,"chars":297},{"level":2,"title":"Related information","slug":"related-information","at":13104,"chars":216}],"text":"# HttpClient.Post(Text, HttpContent, var HttpResponseMessage) Method\n> Version: _Available or changed with runtime version 1.0._\nSends a POST request to the specified URI as an asynchronous operation.\n## Syntax\n```al\n[Ok := ]  HttpClient.Post(Path: Text, Content: HttpContent, var Response: HttpResponseMessage)\n```\n## Parameters\nHttpClient\nType: httpclient-data-type\nAn instance of the httpclient-data-type data type.\nPath\nType: ../text/text-data-type\nThe path the request is sent to.\nContent\nType: ../httpcontent/httpcontent-data-type\nThe HTTP request content sent to the server.\nResponse\nType: ../httpresponsemessage/httpresponsemessage-data-type\nThe response received from the remote endpoint.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\nAccessing the HttpContent property of HttpResponseMessage in a case when the request fails will result in an error. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.\n## Ways that HttpClient.Post calls can fail\nThe method HttpClient.Post can fail and return false in the following ways:\n The requestUri isn't an absolute URI.\n The request fails because of an underlying issue, like network connectivity, DNS failure, server certificate validation, or timeout.\n The request times out.\n The response exceeds the allowed limit in MiB. For Business Central online, the limit is 150 MiB. For Business Central on-premises, the server setting NavHttpClientMaxResponseContentSize specifies the limit, which is 150 MiB by default.\n> IMPORTANT\n> Outbound HTTP calls from apps/extensions are blocked by default and must be approved for each extension, otherwise instead of an external call, the system will display the following error message: The request was blocked by the runtime to prevent accidental use of production services.\n> To enable outbound HTTP calls, go to the Extension Management page in Business Central, and choose Configure. Then, on the Extension Settings page, make sure that Allow HttpClient Requests is selected. This setting must be enabled for each app/extension, including library apps.\n## Example (HTTP POST)\nA POST request sends data to the server for processing. The Content-Type header of the request signifies what MIME type the body is sending. To make an HTTP POST request, given an HttpClient and a Uri, use the HttpClient.Post method:\n```al\n    local procedure PostRequest(json: Text;) ResponseText: Text\n    var\n        Client: HttpClient;\n        Content: HttpContent\n        ContentHeaders: HttpHeaders;\n        IsSuccessful: Boolean;\n        Response: HttpResponseMessage;\n        ResponseText: Text;\n    begin\n        Content.GetHeaders(ContentHeaders);\n\n        if ContentHeaders.Contains('Content-Type') then headers.Remove('Content-Type');\n        ContentHeaders.Add('Content-Type', 'application/json');\n\n        // assume that the json parameter contains the following data\n        //\n        // {\n        //    userId = 77,\n        //    id = 1,\n        //    title = \"write code sample\",\n        //    completed = false\n        // }\n        Content.WriteFrom(json);\n\n        IsSuccessful := Client.Post('https://jsonplaceholder.typicode.com/todos', Content, Response);\n\n        if not IsSuccessful then begin\n            // handle the error\n        end;\n\n        if not Response.IsSuccessStatusCode() then begin\n            HttpStatusCode := response.HttpStatusCode();\n            // handle the error (depending on the HTTP status code)\n        end;\n\n        Response.Content().ReadAs(ResponseText);\n\n        // Expected output:\n        //   POST https://jsonplaceholder.typicode.com/todos HTTP/1.1\n        //   {\n        //     \"userId\": 77,\n        //     \"id\": 201,\n        //     \"title\": \"write code sample\",\n        //     \"completed\": false\n        //   }\n    end;\n```\nThe preceding code:\n Prepares an HttpContent instance with the JSON body of the request (MIME type of \"application/json\" and using the character encoding UTF8).\n Makes a POST request to \"https://jsonplaceholder.typicode.com/todos\".\n Ensures that the response is successful.\n Reads the response body as a string.\n## Example (How to upload a file using multipart/form-data)\nThe Content-Type _multipart/form-data_ allows you to post multiple types of data in the same HTTP request and is commonly used for streaming data to an endpoint.\nTo use multipart/form-data with Httpclient, you need to do the following:\n1. Create a content payload, including defining the boundary between data elements.\n2. Add the file content and file name to the content payload.\n3. Set up the HTTP content header multipart/form-data.\nAfter these steps, your AL code should follows usual practices for Httpclient POST requests.\nThe methods for adding file content to the content payload differs depending if the file is a text file such as JSON or XML, or if it's a binary file. So we provided two different code examples below, one for each scenario:\n### Example (How to upload a text file using multipart/form-data)\n```al\n    procedure UploadJson(json: Text; Url: Text)\n    var\n        Client: HttpClient;\n        Content: HttpContent;\n        Headers: HttpHeaders;\n        Response: HttpResponseMessage;\n        MultiPartBody: TextBuilder;\n        Boundary: Text;\n        ResponseMessage: Text;\n    begin\n        Boundary := CreateGuid();\n        MultiPartBody.AppendLine('--' + Format(Boundary));\n        MultiPartBody.AppendLine('Content-Disposition: form-data; name=\"<add your formname here>\"');\n        MultiPartBody.AppendLine();\n        MultiPartBody.AppendLine('--' + Format(Boundary));\n        MultiPartBody.AppendLine('Content-Disposition: form-data; name=\"file\"; filename=\"<add filename here>\"');\n        MultiPartBody.AppendLine('Content-Type: application/octet-stream');\n        MultiPartBody.AppendLine();\n        MultiPartBody.AppendLine(json);\n        MultiPartBody.AppendLine('--' + Format(Boundary) + '--');\n\n        Content.WriteFrom(MultiPartBody.ToText());\n\n        Content.GetHeaders(Headers);\n        if Headers.Contains('Content-Type') then\n            Headers.Remove('Content-Type');\n        Headers.Add('Content-Type', 'multipart/form-data; boundary=\"' + Format(Boundary) + '\"');\n\n        IsSuccessful := Client.Post(Url, Content, Response);\n\n        if not IsSuccessful then begin\n            // handle the error\n        end;\n\n        if not Response.IsSuccessStatusCode() then begin\n            HttpStatusCode := response.HttpStatusCode();\n            // handle the error (depending on the HTTP status code)\n        end;\n\n    end;\n```\n### Example (How to upload a binary file using multipart/form-data)\nThe main reason for the code example being different when dealing with binary data is that we need to preserve the encoding of the data. A conversion to text might change the encoding.\n```al\n    procedure UploadBinaryFile(ContentToBeUploaded: InStream; Url: Text)\n    var\n        Client: HttpClient;\n        Content: HttpContent;\n        Headers: HttpHeaders;\n        Response: HttpResponseMessage;\n        MultiPartBody: TextBuilder;\n        MultiPartBodyOutStream: OutStream;\n        MultiPartBodyInStream: InStream;\n        TempBlob: Record TempBlob temporary;\n        Boundary: Text;\n        ResponseMessage: Text;\n    begin\n        TempBlob.Blob.CreateOutStream(MultiPartBodyOutStream);\n\n        Boundary := CreateGuid();\n        MultiPartBody.AppendLine('--' + Format(Boundary));\n        MultiPartBody.AppendLine('Content-Disposition: form-data; name=\"<add your formname here>\"');\n        MultiPartBody.AppendLine();\n        MultiPartBody.AppendLine('--' + Format(Boundary));\n        MultiPartBody.AppendLine('Content-Disposition: form-data; name=\"file\"; filename=\"<add filename here>\"');\n        //add file Content-Type eg. image/jpeg, image/png. If not known, use application/octet-stream.\n        MultiPartBody.AppendLine('Content-Type: <add file Content-Type here>');\n        MultiPartBody.AppendLine();\n        MultiPartBodyOutStream.WriteText(MultiPartBody.ToText());\n\n        CopyStream(MultiPartBodyOutStream, ContentToBeUploaded);\n\n        MultiPartBody.Clear();\n        MultiPartBody.AppendLine();\n        MultiPartBody.AppendLine('--' + Format(Boundary) + '--');\n        MultiPartBodyOutStream.WriteText(MultiPartBody.ToText());\n\n        TempBlob.Blob.CreateInStream(MultiPartBodyInStream);\n        Content.WriteFrom(MultiPartBodyInStream);\n\n        Content.GetHeaders(Headers);\n        if Headers.Contains('Content-Type') then\n            Headers.Remove('Content-Type');\n        Headers.Add('Content-Type', 'multipart/form-data; boundary=\"' + Format(Boundary) + '\"');\n\n        IsSuccessful := Client.Post(Url, Content, Response);\n\n        if not IsSuccessful then begin\n            // handle the error\n        end;\n\n        if not Response.IsSuccessStatusCode() then begin\n            HttpStatusCode := response.HttpStatusCode();\n            // handle the error (depending on the HTTP status code)\n        end;\n\n    end;\n```\n### Example (How to upload large files using multipart/form-data)\nSome endpoints have restrictions on the size of files that can be uploaded and hence you might need to split and upload the file in chunks. The system application SharePoint module has an implementation for how to achieve this. See Share Point module<https://github.com/microsoft/BCApps/tree/main/src/System%20Application/App/SharePoint>.\n## Content headers\nBy default, the content headers contain a header for 'Content-Type', namely 'text/plain; charset=utf-8'. This is important to adjust if the endpoint you're calling expects a different content type, for example, multipart/form-data or application/json.\nThe following AL code examples illustrate ways to change the content header.\n```al\n    local procedure SendRequest(HttpMethod: Text[6]) ResponseText: Text\n    var\n        Client: HttpClient;\n        Content: HttpContent;\n        ContentHeaders: HttpHeaders;\n    begin\n        Content.GetHeaders(ContentHeaders);\n\n        // If you want to set all the headers yourself, do it this way\n        ContentHeaders.Clear();\n        ContentHeaders.Add('Content-Type', 'multipart/form-data;boundary=boundary');\n\n        // from here on, the method must deal with calling out to the external service.\n    end;\n```\n```al\n    local procedure SendRequest(HttpMethod: Text[6]) ResponseText: Text\n    var\n        Client: HttpClient;\n        Content: HttpContent;\n        ContentHeaders: HttpHeaders;\n    begin\n        Content.GetHeaders(ContentHeaders);\n\n        // In this example, you just change the headers you need\n        if ContentHeaders.Contains('Content-Type') then ContentHeaders.Remove('Content-Type');\n        ContentHeaders.Add('Content-Type', 'multipart/form-data;boundary=boundary');\n\n        // from here on, the method must deal with calling out to the external service.\n    end;\n```\nWhen calling an endpoint, you get a response back from the service you called. The response is saved in the data type HttpResponseMessage, where you can parse it to use the information in your app. The service call itself might not succeed, so make sure that you check the HTTP status code in your AL code. In the case of setting the wrong content type header, you'll typically receive the _415 Unsupported Media Type_ return code. This return code can also be due to the request's _Content-Encoding_ header, or if the data you send doesn't match what the endpoint expects.\n## Supported HTTP methods\nThe HttpClient datatype supports the following HTTP methods:\n DELETE\n GET\n PATCH\n POST\n PUT\nThe following table includes links to help you get started with calling external services using different HTTP methods.\nTo|See\nDynamically set the HTTP method from AL, set it on the HttpRequestMessage datatype and use the HttpClient.Send method to call the service.|HttpClient.Send(HttpRequestMessage, var HttpResponseMessage) Method<httpclient-send-method> <br> HttpRequestMessage.Method([Text]) Method<../httprequestmessage/httprequestmessage-method-method>\nDelete data in a service endpoint using the HTTP DELETE method.|HttpClient.Delete(Text, var HttpResponseMessage) Method<httpclient-delete-method>\nRead data from a service endpoint using the HTTP GET method.|HttpClient.Get(Text, var HttpResponseMessage) Method<httpclient-get-method>\nUpdate data in a service endpoint using the HTTP PATCH method (no specific AL method exists for PATCH, so use HttpClient.Send).|HttpClient.Send(Text, HttpContent, var HttpResponseMessage) Method<httpclient-send-method>\nSend data to a service endpoint using the HTTP POST method.|HttpClient.Post(Text, HttpContent, var HttpResponseMessage) Method<httpclient-post-method>\nSend data to a service endpoint using the HTTP PUT method.|HttpClient.Put(Text, HttpContent, var HttpResponseMessage) Method<httpclient-put-method>\n## Contributors\nThis article is maintained by Microsoft. Parts of the examples were originally written by the following contributors.\n Michael Megel<https://www.linkedin.com/in/michaelmegel/> | Microsoft MVP\n Nikolay Arhangelov<https://www.linkedin.com/in/nikolay-arhangelov/> | Technical Manager\n## Related information\nCall external services with the HttpClient data type<../../devenv-httpclient>\nhttpclient-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}