使用API​​的WebRespons中出现[C#]错误 [英] [C#] Error in WebRespons using API

查看:180
本文介绍了使用API​​的WebRespons中出现[C#]错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用此网站的MacVendorLookUp API: http: //www.macvendorlookup.com [ ^ ]



错误:

System.dll中发生了'System.Net.WebException'类型的未处理异常



附加信息:远程服务器返回错误(407)需要代理验证。



错误代码:

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:

WebResponse response = request.GetResponse();





完整的C#事件代码:





Full C# event code:

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..

推荐答案

您好,



您需要提供代理服务器的凭证和请求。



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



获取默认代理: http://msdn.microsoft.com/en-us/library/system.net.webproxy.getdefaultproxy(V = vs.110)的.aspx [ ^ ]



将凭据设置为HttpWebRequest。
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.


这篇关于使用API​​的WebRespons中出现[C#]错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆