Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

setting httpwebrequest content length in NAV17

Posted on by 20

Hi Community , 

when setting up HttpWebRequest ContentLength as shown in the code below, i found that there's no ContentLength attribute for HttpWebRequest. Add to that i had an error message to initialize the StatusCode before using it. AnyOne can help please ? 

GetToken() Token : Text
  SharepointSetup_L.GET(USERID);
  granttype:=SharepointSetup_L."Grant Type";
  clientid:=SharepointSetup_L.Client_Id '@'  SharepointSetup_L.Tenant;
  ClientSecret:=SharepointSetup_L."Client Secret";
  resources := SharepointSetup_L.Resources   '/'   SharepointSetup_L.Domain   '.sharepoint.com@'   SharepointSetup_L.Tenant;
  tenant := SharepointSetup_L.Tenant; 
  RequestURI_L := 'https://accounts.accesscontrol.windows.net/'   tenant   '/tokens/oAuth/2';
  PostData :='grant_type='   TypeHelper.UrlEncode(granttype)   '&client_id='  TypeHelper.UrlEncode(clientid)   '&client_secret='   TypeHelper.UrlEncode(ClientSecret) '&resource='   TypeHelper.UrlEncode(resources);
  HttpWebRequest_L.Initialize(RequestURI_L);
  HttpWebRequest_L.DisableUI;
  HttpWebRequest_L.SetTimeout(300000);
  HttpWebRequest_L.SetMethod('POST');
  HttpWebRequest_L.SetContentType('application/x-www-form-urlencoded');
//  HttpWebRequest_L.ContentLength := RequestString.Length;
  SetRequestStream(HttpWebRequest, PostData);
  HttpWebRequest_L.GetResponseStream(InStr);
  HttpWebResponse.StatusCode := HttpWebResponse.StatusCode;
  IF FORMAT(HttpWebResponse.StatusCode) = 'OK' THEN
  BEGIN
    Streamreader := Streamreader.StreamReader(InStr);
    JSonString := Streamreader.ReadToEnd;
    
  END

pastedimage1667470218019v1.png

  • Suggested answer
    Andy Sather Profile Picture
    Andy Sather on at
    RE: setting httpwebrequest content length in NAV17

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    I will open this up to the community in case they have something to add.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans