Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

How to handle webRequest Error?

Posted on by Microsoft Employee

Hi All,

I have an issue when i got error from HttpWebResponse it's shows always "Remote server can be found (400) : Bad request" but this is not my exact error means that my error is Email address is not valid or customer already exist.

i got an correct response in NAV 2016 with in bulit dll's like system.net.http and i con't find this dll in NAV 2009 R2 and my solution will not work this error message getting part because of dll so for that by R&D i found below link

http://www.dynamics.is/?p=1255

as per above link i tried and same error "Remote server can be found (400) : Bad request"  it's not my exact error.

so please provide any solution for this.

Thank You

ramesh

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to handle webRequest Error?

    Hi Ramesh,

    did you get a solution to your error? I am having the same problem. Thanks

  • ManishS Profile Picture
    ManishS 6,578 on at
    RE: How to handle webRequest Error?

    you can user XMLdoc & XMLhttp automation.

  • Verified answer
    keoma Profile Picture
    keoma 32,675 on at
    RE: How to handle webRequest Error?

    for usage with nav 2009 you need an older version of system.net.http. system.net.http is not part of .net framework, it's an additional library from nuget.

    for the older version of system.net.http, which is usable with .net framework 2.0/3.5, goto

    www.nuget.org/.../2.0.20710 and

    www.nuget.org/.../2.0.20710

    alternatively you could try to develope a code without using these nuget libraries.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to handle webRequest Error?

    Hi Manish,

    i have tested restful client i got error message Remote server can not be found(404):Bad request but not an exact error for getting exact error i written code please see reply what i have given to Jonathan.

    the code i have written in nav 2016  with advanced dll's how should i get this exact dll in nav 2009 R2 too.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to handle webRequest Error?

    Hi Jonathan,

    i have used same HttpWebResponse when i get the response

    HttpWebResponse := HttpWebRequest.GetResponse;

    in the above statement i got an error "Remote server can be found (404) : Bad request" but this is not an exact error Email address not exist my error to get an exact error message i have used System.net.Http dll see below my code

    HttpContent := StringContent.StringContent(Json,SText.UTF8,'application/json');

    HttpClient := HttpClient.HttpClient;

    HttpClient.DefaultRequestHeaders.Authorization := HttpHeader.AuthenticationHeaderValue('Bearer','xg7s6d17jc70l6vebduhyxjugp4a78hk');

    HttpResponseMessage := HttpResponseMessage.HttpResponseMessage;

    IF MagentoConnectionP."HTTP Request Method" = 'POST' THEN

      HttpResponseMessage := HttpClient.PostAsync(MagentoRestAPIURL,HttpContent).Result;

    IF MagentoConnectionP."HTTP Request Method" = 'PUT' THEN

      HttpResponseMessage := HttpClient.PutAsync(MagentoRestAPIURL,HttpContent).Result;

    IF MagentoConnectionP."HTTP Request Method" = 'GET' THEN

      HttpResponseMessage := HttpClient.GetAsync(MagentoRestAPIURL).Result;

    HandleText := HttpResponseMessage.Content.ReadAsStringAsync().Result;

    ERROR(HandleText);

    see dll variables i used here

    Name DataType Subtype Length

    HttpResponseMessage DotNet System.Net.Http.HttpResponseMessage.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    HttpClient DotNet System.Net.Http.HttpClient.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    HttpContent DotNet System.Net.Http.HttpContent.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    StringContent DotNet System.Net.Http.StringContent.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    HttpHeader DotNet System.Net.Http.Headers.AuthenticationHeaderValue.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    All the variables belongs to System.Net.Http dll but i con't find this dll in nav 2009 R2 is there any alternate solution for this.

    Thank You

    Ramesh

  • ManishS Profile Picture
    ManishS 6,578 on at
    RE: How to handle webRequest Error?

    Have you used postmaster google addon to check the response and request.

    May be your request is not correct.

  • Suggested answer
    keoma Profile Picture
    keoma 32,675 on at
    RE: How to handle webRequest Error?

    for usage with nav 2009 you need .net framework 2.0 (3.5). won't work with newer .net frameworks.

    System.Net.HttpWebResponse also exists in .net 2.0, assembly System.dll:

    'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebResponse

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans