Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#

I am using a MacVendorLookUp API from this site: http://www.macvendorlookup.com[^]

Error:
"An unhandled exception of type 'System.Net.WebException' occurred in System.dll

Additional information: The remote server returned an error (407) Proxy Authentication Required."

Error in code:
C#
WebResponse response = request.GetResponse();


Full C# event code:

C#
private void findvendorButton_Click(object sender, EventArgs e)
        {
            string cell = "";
            System.IO.StreamReader reader;
            WebRequest request = WebRequest.Create("http://www.macvendorlookup.com/api/v2/{" + macaddressTextBox.Text + "}");
            request.Timeout = 120000;
            WebResponse response = request.GetResponse();
            reader = new System.IO.StreamReader(response.GetResponseStream());
            string get = reader.ReadToEnd();
            MatchCollection m1 = Regex.Matches(get, @"(company)(.*?)(}])", RegexOptions.Singleline);
            foreach (Match m in m1)
            {
                cell = m.Groups[0].Value;
            }
            vendorTextBox.Text = cell.Trim().Split('\"')[2].ToString();
        }


Anyone knows what i can do to prevent this error?
Sometimes i get the error, and sometimes i don't.. I don't understand..
Posted

1 solution

Hi,

You Need to provide credentials of your proxy server with the request.

Example : http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.credentials(v=vs.110).aspx[^]

Get default Proxy : http://msdn.microsoft.com/en-us/library/system.net.webproxy.getdefaultproxy(v=vs.110).aspx[^]

Set the credentials to HttpWebRequest.
 
Share this answer
 
Comments
Fail4FunTV 9-Oct-14 4:50am    
I don't get how to implement it into my code(?)
Suvabrata Roy 9-Oct-14 6:39am    
WebRequest request = WebRequest.Create("http://www.macvendorlookup.com/api/v2/{" + macaddressTextBox.Text + "}");
request.Credentials = new NetworkCredential("ProxyUserName", "Password");
request.Timeout = 120000;
Fail4FunTV 9-Oct-14 7:17am    
NetworkCredential("ProxyUserName", "Password"); ?

What is ProxyUserName and Password?
Suvabrata Roy 9-Oct-14 7:36am    
How I could know that Ask your It Infra team.

Or pick default proxy.
Fail4FunTV 9-Oct-14 7:47am    
What is default proxy?

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