Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If am using below code to get authentication response from service.
C#
using (var client = new HttpClient())
{
	client.BaseAddress = new Uri
	var content = new FormUrlEncodedContent(new[] 
	{
		new KeyValuePair<string,>("username", _username),
		new KeyValuePair<string,>("password", _password)
	});
	var response = client.PostAsync("api/authorize", content).Result;
}

However getting aggregate exception and inside it, below exceptions are given:
{"An error occurred while sending the request."}
{"Unable to connect to the remote server"}
{"No connection could be made because the target machine actively refused it 216.167.113.4:443"}

Have gone through some of the forums and one of the possible reason could be Firewall ( on which i have no rights to put it on in OFF mode)
But if I am able to access the same service through browser I am able to access.
So not sure whether its a firewall problem or not. Can anyone please suggest or guide me, how can I be sure of the root cause of this problem.

Struggling a lot with this issue, please help me out
Posted
Updated 29-Jul-15 1:53am
v2
Comments
Kornfeld Eliyahu Peter 29-Jul-15 7:55am    
Maybe you are using different credentials while testing the code from the one you have in the browser (check IIS user)?
anoopsingh.hada 30-Jul-15 3:29am    
Through browser as well as through code, I am using same credentials. Could you please give more details? if my response is not as per your expectation :-)
Mathi Mani 29-Jul-15 16:59pm    
Usually authentication details will be sent as part of request header. You are sending as the content. Try changing that. This tip might help you http://www.codeproject.com/Tips/996401/Authenticate-WebAPIs-with-Basic-and-Windows-Authen
anoopsingh.hada 30-Jul-15 3:30am    
Tried the tip, but it didn't helped. Same exception.
Chandan Choubey 14-Jul-16 21:58pm    
I am having the same trouble too. In my case this is intermittent.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900