how to HTTP request POST in AL ?

julkifli33julkifli33 Member Posts: 1,092
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 Member Posts: 308
    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 Member Posts: 1,092
    Hi Wisa thanks for the link !
  • julkifli33julkifli33 Member Posts: 1,092
    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 Member Posts: 1,092
    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.