我试图通过使用HttpWebRequest发送xml文档并使用C#ASP.net基于Web的应用程序中的HttpWebResponse接收来自UIDAI数据中心的响应xml。我已经使用java应用程序检查了它,它可以正常工作,但基于Web的应用程序正在抛出异常
System.dll中出现“System.Net.WebException”类型的异常,但未在用户代码中处理
注意:Web异常发生在最后一行的第5行
请提供一些方法来解决此问题
public void SendForAuthentication()//user defined function for Sending and Receiving Requests
{
string url = "http://auth.uidai.gov.in/1.6/public/9/9/MLTbKYcsgYMq1zgL3WMZYrnyvsarlljxpom2A-QTPc0Zud23shpnqPk";//the host address
StreamReader sr1 = new StreamReader("D:\\test-signed.xml");//loading xml file to stream
string XMLData = sr1.ReadToEnd();
string Conn = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>";
XMLData = Conn + XMLData;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
byte[] requestBytes = System.Text.Encoding.UTF8.GetBytes(XMLData);
req.Method = "POST";
req.ContentType = "text/xml;charset=utf-8";
req.ContentLength = requestBytes.Length;
Stream requestStream = req.GetRequestStream();
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)req.GetResponse();//**here I am getting a webexception**
StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);
string backstr = sr.ReadToEnd();
reader.ReadToFollowing("title");
File.WriteAllText("D:\\xml.xml", backstr);
}
编辑: 虽然我增加了操作时间,但我得到的例外是“操作已经超时”
EDIT2: 上面的代码工作正常,我的防火墙实际上有问题