首页  ·  知识 ·  云计算
通过http/https的POST方式,发送、处理和接收XML文件内容
lee576  博客园 http://blog.csdn.net/lee576/  综合  编辑:德仔   图片来源:网络
1.send: dl code sizset=19 sizcache=1dtC# code /d
1.send:

C# code
WebRequest myHttpWebRequest = WebRequest.Create("http://abc.com/xxx.aspx");
// Set the 'Method' property of the 'Webrequest' to 'POST'.
myHttpWebRequest.Method = "POST";

// Create a new string object to POST data to the Url.
string postData = @"<?xml version="1.0" encoding="UTF-8" ?>
<ROOT>
<CONFIG>
<TYPE>IN </TYPE>
<WORKTYPE>2 </WORKTYPE>
</CONFIG>
<DATA>
<POLICY>
<UNITCODE>分公司代码 </UNITCODE>
<APPLYNO>投保单号码 </APPLYNO>
<APPLYENDORSENO>批单申请号码 </APPLYENDORSENO>
</POLICY>
</DATA>
</ROOT> ";

ASCIIEncoding encoding
= new ASCIIEncoding ();
byte[] byte1 = encoding.GetBytes (postData);

// Set the content type of the data being posted.
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";

// Set the content length of the string being posted.
myHttpWebRequest.ContentLength = byte1.Length;

Stream newStream
= myHttpWebRequest.GetRequestStream ();

newStream.Write (byte1,
0, byte1.Length);
// Close the Stream object.
newStream.Close ();

HttpWebResponse response
= myHttpWebRequest.GetResponse();



2.receive:

C# code
StreamReader reader = new StreamReader (Reqeust.InputStream);
String xml
= reader.ReadToEnd();
本文作者:lee576 来源:博客园 http://blog.csdn.net/lee576/
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读