如何使用网络将XML文件发送到另一台服务器?

时间:2012-11-01 03:21:50

标签: c# web-services webrequest

我有一个xml文件,我想使用net work将它发送到另一台服务器。 所以我写下面的代码

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”文件?

0 个答案:

没有答案