Click here to Skip to main content
15,888,590 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I am using my C# application to send SMS through web service. During the execution of my code, when control reaches to try catch block,that is req.GetResponse() i am getting an error
Error is - "The remote server returned an error:(407)Proxy authentication required"

The code what i have written is
C#
string url = "valid url";

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

NetworkCredential netcredit = new NetworkCredential("username",    "password", "domain");

req.Credentials = netcredit;

System.Net.WebProxy pry = new WebProxy("192.168.1.4:1598", true);

pry.Credentials = netcredit;

req.Proxy = pry;

req.Method = "HEAD";

try
{
    HttpWebResponse res = (HttpWebResponse)req.GetResponse();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
    return;
}

Please help to solve this error

rgds
Posted
Updated 14-Feb-12 23:03pm
v2

Dear Friend,

Either the credentials you are providing are incorrect or Check with your firewall expert. They open the firewall for PROD servers so there is no need to use the Proxy.
OR

You have to set the Credentials in two locations to get past the 407 error:

HttpWebRequest webRequest = WebRequest.Create(uirTradeStream) as HttpWebRequest;
webRequest.Proxy = WebRequest.DefaultWebProxy;
webRequest.Credentials = new NetworkCredential("user", "password", "domain");
webRequest.Proxy.Credentials = new NetworkCredential("user", "password", "domain")


If the above things don't work out then follow the link

http://blogs.msdn.com/b/jpsanders/archive/2009/03/24/httpwebrequest-webexcepton-the-remote-server-returned-an-error-407-proxy-authentication-required.aspx[^]

Don't forget to mark this as your answer if it helps you out.

Thanks
 
Share this answer
 
Comments
code4Better 15-Feb-12 6:33am    
Dear varun,
Is there any problem with my code ?
code4Better 15-Feb-12 6:42am    
i tried to use
req.Credentials = netcredit;
req.Proxy.Credentials = netcredit;
but still i am getting same error ?
Varun Sareen 16-Feb-12 12:55pm    
I haven't tried your code but given an alternative solution to it. You try it atleast once and if you face problem then you can ask anytime
Varun Sareen 15-Feb-12 8:17am    
Dear Friend,

Please try the thing that i have sent to you it has worked for many
Check if this thread on StackOverFlow is of any help.
407 proxy authentication required[^]
 
Share this answer
 
when i remove domain name from networkwork credentaial it works
 
Share this answer
 
Comments
Varun Sareen 16-Feb-12 1:45am    
good

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