{"title":"HttpClient.Send(HttpRequestMessage, var HttpResponseMessage) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/httpclient/httpclient-send-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-send-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-send-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 an HTTP request as an asynchronous operation.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"HttpClient.Send(HttpRequestMessage, var HttpResponseMessage) Method","slug":"httpclientsendhttprequestmessage-var-httpresponsemessage-method","at":0,"chars":8170},{"level":2,"title":"Syntax","slug":"syntax","at":182,"chars":110},{"level":2,"title":"Parameters","slug":"parameters","at":292,"chars":318},{"level":2,"title":"Return Value","slug":"return-value","at":610,"chars":299},{"level":2,"title":"Ways that HttpClient.Send calls can fail","slug":"ways-that-httpclientsend-calls-can-fail","at":909,"chars":1178},{"level":2,"title":"Example (HTTP PATCH)","slug":"example-http-patch","at":2087,"chars":2457},{"level":2,"title":"Content headers","slug":"content-headers","at":4544,"chars":2031},{"level":2,"title":"Supported HTTP methods","slug":"supported-http-methods","at":6575,"chars":1379},{"level":2,"title":"Related information","slug":"related-information","at":7954,"chars":216}],"text":"# HttpClient.Send(HttpRequestMessage, var HttpResponseMessage) Method\n> Version: _Available or changed with runtime version 1.0._\nSends an HTTP request as an asynchronous operation.\n## Syntax\n```al\n[Ok := ]  HttpClient.Send(Request: HttpRequestMessage, var Response: HttpResponseMessage)\n```\n## Parameters\nHttpClient\nType: httpclient-data-type\nAn instance of the httpclient-data-type data type.\nRequest\nType: ../httprequestmessage/httprequestmessage-data-type\nThe HTTP request message to send.\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.Send calls can fail\nThe method HttpClient.Send can fail and return false in the following ways:\n The chosen HTTP method is not supported.\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 PATCH)\nAs an example of how to use the HttpClient.Send, we illustrate how to do an HTTP PATCH request. Examples of the other supported HTTP methods (DELETE, GET, POST, or PUT), see the respective articles for their methods (HttpClient.Delete, HttpClient.Get, HttpClient.Post, or HttpClient.Put).\nThe PATCH request is a partial update to an existing resource. It doesn't create a new resource, and it's not intended to replace an existing resource. Instead, it updates a resource only partially. To make an HTTP PATCH request, given an HttpClient and a URI, use the HttpClient.Send method:\n```al\nlocal procedure PatchRequest(json: Text) ResponseText: Text\nvar\n    Client: HttpClient;\n    Content: HttpContent;\n    ContentHeaders: HttpHeaders;\n    RequestMessage: HttpRequestMessage;\n    Response: HttpResponseMessage;\n    IsSuccessful: Boolean;\nbegin\n    Content.GetHeaders(ContentHeaders);\n\n    if ContentHeaders.Contains('Content-Type') then ContentHeaders.Remove('Content-Type');\n    ContentHeaders.Add('Content-Type', 'application/json');\n\n    if ContentHeaders.Contains('Content-Encoding') then ContentHeaders.Remove('Content-Encoding');\n    ContentHeaders.Add('Content-Encoding', 'UTF8');\n\n    // assume that the json parameter contains the following data\n    //\n    // {\n    //    title = \"updated title\",\n    //    completed = true\n    // }\n    Content.WriteFrom(json);\n\n    RequestMessage.SetRequestUri('https://jsonplaceholder.typicode.com/todos/1');\n    RequestMessage.Method('PATCH');\n    RequestMessage.Content(Content);\n\n    IsSuccessful := Client.Send(RequestMessage, 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    //   PATCH https://jsonplaceholder.typicode.com/todos/1 HTTP/1.1\n    //   {\n    //     \"userId\": 1,\n    //     \"id\": 1,\n    //     \"title\": \"updated title\",\n    //     \"completed\": true\n    //   }\nend;\n```\nThe preceding code:\n Prepares a HttpContent instance with the JSON body of the request (MIME type of \"application/json\" and using the character encoding UTF8).\n Makes a PATCH request to \"https://jsonplaceholder.typicode.com/todos/1\".\n Ensures that the response is successful.\n Reads the response body as a string.\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## 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>"}