How to handle webRequest Error?

Question Status

Suggested Answer
ramesh reddy asked a question on 21 Apr 2017 4:46 AM

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

Reply
Suggested Answer
Jonathan Archer responded on 21 Apr 2017 4:54 AM

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

Reply
Manish Sharma responded on 21 Apr 2017 4:58 AM

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

May be your request is not correct.

Reply
ramesh reddy responded on 21 Apr 2017 5:07 AM

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

Reply
ramesh reddy responded on 21 Apr 2017 5:11 AM

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.

Reply
Suggested Answer
Jonathan Archer responded on 21 Apr 2017 1:22 PM

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.

Reply
Manish Sharma responded on 29 Apr 2017 6:10 AM

you can user XMLdoc & XMLhttp automation.

Reply
Suggested Answer
Jonathan Archer responded on 21 Apr 2017 4:54 AM

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

Reply
Suggested Answer
Jonathan Archer responded on 21 Apr 2017 1:22 PM

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.

Reply