I am developing an ASP.NET MVC application. There I consume an API service via System.Net.Http.HttpClient. Here is the controller that performs the job
private readonly HttpClient _client;
public HomeController()
{
_client = new HttpClient()
}
public async Task<ActionResult> Index(SearchParam searchParam)
{
// API Initialization
_client.DefaultRequestHeaders.Clear();
_client.BaseAddress = new Uri(Uri);
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// API Consumption By HttpClinet
var url = _searchService.GetApiQueryParams(searchParam);
var response = await _client.GetAsync(url);
var jsonString = await response.Content.ReadAsStringAsync();
var rootobject = JsonConvert.DeserializeObject<Response.Rootobject>(jsonString);
if (response.StatusCode == HttpStatusCode.OK)
{
var searchResults = _searchService.GetSearchResults(rootobject, searchParam);
return View("SearchResult", searchResults);
}
ModelState.AddModelError(string.Empty, "Sorry some internal error occur !");
return View("SearchResult");
}
This works fine on my Local Server as well as on an IIS Server. But when I publish the application to a different hosting Server and try to consume the API it shows this error.
I have found two similar issue. Please have a look at these
- SocketException (0x274c) while accessing service with HttpClient
- https://support.microsoft.com/en-us/help/318140/prb-error-on-net-client-that-consumes-a-web-service-through-an-http-pr
From the first issue, I didn't get the "load balancer to the server".
And from the second issue when I add the solution in the Web.config it shows an error for proxyaddress="http://proxyserver" which make sense.
Now I am badly in need of a solution to this problem. I am not good at questing, so please feel free to suggest or correct any error.