how to HTTP request POST in AL ?

julkifli33julkifli33 Posts: 900Member
Hi All
how do i do http request POST?
actually i generate 1 xml file in for example C:\Test Folder\
and then i want to post this file to this API
POST https://qekzvwip-40Xv44445s2mhtti.azure-api.net/api/invoices HTTP/1.1
Host: qekzvwip-40Xv44445s2mhtti.azure-api.net
Content-Type: application/json
Ocp-Apim-Subscription-Key: ••••••••••••••••••••••••••••••••

{
  "header": {
    "sender": "0195:SGUEN199802208C",
    "receiver": "0195:SGUEN200908484S"
  },
  "body": {
    "Message": ""
  }
}

Thanks before

Answers

  • Wisa123Wisa123 Posts: 267Member
    edited 2019-12-02
    Hi,
    Use the new HTTPClient Data Type introduced in Business Central.
    HTTP Client Datatype on msdn
    Similar question

    /Wisa
    Austrian NAV/BC Dev
  • julkifli33julkifli33 Posts: 900Member
    Hi Wisa thanks for the link !
  • julkifli33julkifli33 Posts: 900Member
    POST
    Content.WriteFrom(PayloadInStream);
            Content.GetHeaders(ContentHeaders);
            ContentHeaders.Remove('Content-Type');
            ContentHeaders.Add('Content-Type', 'application/json');
            ContentHeaders.Add('Ocp-Apim-Subscription-Key', SubscriptionKey);
            Client.SetBaseAddress(Url);
            Client.Post(Url, Content, Response);
    
  • julkifli33julkifli33 Posts: 900Member
    GET
     Content.GetHeaders(ContentHeaders);
            Client.DefaultRequestHeaders.Add('Ocp-Apim-Subscription-Key', SubscriptionKey);
            Client.Get(URL, Response);
            Response.Content().ReadAs(RetValueMessage)
    
Sign In or Register to comment.