Response status code does not indicate success: 400 (Bad Request).

Raed Hasan 1 Reputation point

i created a page since awhile (1 year) and hosted as App Service on Azure and i call a API and process a JSON response and everything was working normally but since 2 days i start getting this error when call , and this error happen only when open the page from published URL but when open it from local server before publishing its working normally, any idea why this start happening

string json = new WebClient().DownloadString(string.Format("{0}",apicode));

The remote server returned an error: (400) Bad Request.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[WebException: The remote server returned an error: (400) Bad Request.]
System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) +298
System.Net.WebClient.DownloadString(Uri address) +106
System.Net.WebClient.DownloadString(String address) +32
JordanMeteo.ZohorRealtime.GetRealtimeText() in c:\JordanMeteo\JordanMeteo\JordanMeteo\ZohorRealtime.aspx.cs:220
JordanMeteo.ZohorRealtime.ShowRecords() in c:\JordanMeteo\JordanMeteo\JordanMeteo\ZohorRealtime.aspx.cs:511
JordanMeteo.ZohorRealtime.Page_Load(Object sender, EventArgs e) in c:\JordanMeteo\JordanMeteo\JordanMeteo\ZohorRealtime.aspx.cs:179
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +52
System.Web.UI.Control.OnLoad(EventArgs e) +97
System.Web.UI.Control.LoadRecursive() +61
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +693

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4494.0

A set of technologies in the .NET Framework for building web applications and XML web services.
1,486 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
8,205 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
4,949 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lex Li (Microsoft) 3,481 Reputation points

    A remote API like can return anything it likes and that's out of your control. You will have to contact the vendor of that API for assistance and they might be able to tell you what's wrong and how to fix.

  2. Raed Hasan 1 Reputation point

    i added <httpRuntime targetFramework="4.8"/> in web.config it back working perfectly in Azure App Service

    0 comments No comments