winform项目中,需要和服务器端接口做数据交换,利用post方式传送zip数据包,包中是压缩的.xml文件.
主要代码实现如下:
//发送
HttpWebRequest httpRequest = WebRequest.Create(string.Format("http://{0}:{1}{2}", __ServerIP, __ServerPort, __ServerVATUP)) as HttpWebRequest;
httpRequest.KeepAlive = true;
httpRequest.ContentType = "text/html";
httpRequest.ContentLength = ArrInvoiceSend.Length;
httpRequest.Headers["NSR"] = __RPID;
httpRequest.Headers["PWD"] = __RPPassword;
httpRequest.Headers["NSRSBH"] = hash["BuyerTaxCode"].ToString();
httpRequest.Headers["FORMAT"] = "zip";
httpRequest.ProtocolVersion = new Version("1.0");
httpRequest.UserAgent = "Mozilla/3.0 (compatible;Indy library) ";
httpRequest.Accept = "text/html, */*";
httpRequest.Method = "POST";
httpRequest.Timeout = 1000000;
//获得后台设置的代理,指定http代理
//WebProxy proxy = new WebProxy("uri", 800);
//proxy.Credentials = new NetworkCredential("username", "password");
//httpRequest.Proxy = proxy;
using (System.IO.Stream requestStream = httpRequest.GetRequestStream())
{
requestStream.Write(ArrInvoiceSend, 0, ArrInvoiceSend.Length);
requestStream.Flush();
}
using (WebResponse response = httpRequest.GetResponse())
{
string strResult = response.Headers["result"];
//处理返回的结果数据...