读取URL型的XML报出这样一个错误,求解!
string url = "http://api.zto.cn/Search-Province.aspx ";
XmlDocument xm = new XmlDocument();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "GET";
using (WebResponse wr = req.GetResponse())//这里报错(Unable to read data from the transport connection)
{
using (StreamReader sr = new StreamReader(wr.GetResponseStream()))
{
string Response = sr.ReadToEnd();
DataTable dt = new DataTable(Response);
DataSet ds = GetDataSetByXml(url);
sr.Close();
xm.LoadXml(Response);
dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] };
dt.Columns.Add("ID", typeof(Int32));
dt.Columns.Add("ProvinceName", typeof(string));
dt = ds.Tables[0];
Update(dt);
}
}
[解决办法]
我试了下,浏览器可以打开,就应该没有问题的。
[解决办法]