winform中使用post方式传送zip数据包

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"];

                              //处理返回的结果数据...

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值