System.Net.WebException:无法解析远程名称 - MVC - ASP.net

时间:2014-05-01 06:26:16

标签: c# asp.net-mvc asp.net-mvc-4 system.net.webexception system.net.httpwebrequest

我想使用HttpWebRequest GetResponse()方法调用一个动作方法。

我的代码是:

string url = http://localhost:1234/Test   //Here "Test" is my action method

     System.Net.HttpWebRequest objRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
                objRequest.Method = "GET";
                objRequest.ContentType = "application/x-www-form-urlencoded";
                objRequest.AllowAutoRedirect = true;
                objRequest.KeepAlive = false;
                objRequest.Timeout = 300000;
    using (System.Net.HttpWebResponse objResponse = (System.Net.HttpWebResponse)objRequest.GetResponse())

但它不起作用。我收到了以下错误。

它会抛出错误:

System.Net.WebException: The remote name could not be resolved: 'example.com' at System.Net.HttpWebRequest.GetResponse()

请帮忙。

谢谢。

0 个答案:

没有答案