我有一个 xml 文件,我想使用网络将它发送到另一台服务器。所以我写下面的代码
private string GetTextFromXMLFile(string file)
{
StreamReader reader = new StreamReader(file);
string ret = reader.ReadToEnd();
reader.Close();
return ret;
}
public ActionResult Index()
{
WebRequest req = null;
WebResponse rsp = null;
try
{
string fileName = Server.MapPath("~\\client-authentication.xml");
string uri = "http://10.3.4.84/";
req = WebRequest.Create(uri);
req.Method = "POST";
req.ContentType = "text/xml\r\n";
StreamWriter writer = new StreamWriter(req.GetRequestStream());
writer.WriteLine(this.GetTextFromXMLFile(fileName));
writer.Close();
rsp = req.GetResponse();
StreamReader sr = new StreamReader(rsp.GetResponseStream());
}
}
但它不起作用。有什么问题?如何发送“client-authentication.xml”文件?