1

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

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.

2
  • Did you try to telnet the API server IP/Port from the place where you have hosted your app? It could be some firewall issues if you are not able to connect using telnet. Commented Jun 2, 2018 at 9:28
  • Actually, I have no idea about telnet in application level Commented Jun 2, 2018 at 9:31

1 Answer 1

1

At last, the problem solved. Mentioning the second issue I emailed the problem to the Hosting provider, they provide a system.net configuration. Using this system.net configuration in Web.config solved the issue.

<system.net>
 <defaultProxy>
  <proxy
    usesystemdefault = "false"
    bypassonlocal="false"
    proxyaddress="http://hosting-provided-proxyaddress-here"
  />
 </defaultProxy>
</system.net>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.