Http上传Xml文件
/// <summary> /// Http上传Xml文件 /// </summary> /// <param name="url">访问url</param> /// <param name="path">文件路径(本地的绝对路径)</param> /// <returns></returns> public string HttpUploadFile(string url, string path) { string result = ""; StreamWriter myWriter = null; HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url); objRequest.Method = "POST"; objRequest.ContentType = "text/xml";//提交xml objRequest.ContentType = "application/x-www-form-urlencoded"; try { XmlDocument doc = new XmlDocument(); doc.Load(path); string data = ConvertXmlToString(doc); myWriter = new StreamWriter(objRequest.GetRequestStream()); myWriter.Write(data); } catch (Exception e) { return e.Message; } finally { myWriter.Close(); } HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse(); using (StreamReader sr = new StreamReader(objResponse.GetResponseStream())) { result = sr.ReadToEnd(); sr.Close(); } return result; }