使用Web服务的HTTP POST

编程入门 行业动态 更新时间:2024-10-28 21:26:11
本文介绍了使用Web服务的HTTP POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在做一些谷歌搜索,只得到关于这个主题的部分成功。我想知道,如果有人可以建议做使用C#发送XML到HTTP服务的HTTP POST的例子。

I have been doing some Google searches and only getting partial successful on this topic. I was wondering if someone could suggest an example of doing an HTTP POST using C# to send XML to HTTP service.

我有一个从数据库中提取数据的ASMX Web服务我保存这些数据的XML文档。现在我有使用SOAP协议HTTP服务发送的XML文档。

I have a asmx web service that extracts data from database and I save that data to XML document. Now I have to send that XML document using SOAP protocol to HTTP service.

我有这部分代码为connectig以服务

I have this part of code for connectig to service

WebRequest myReq = WebRequest.Create("WEB_URL"); System.Net.ServicePointManager.CertificatePolicy = new CertificatePolicyClass(); string username = "SOMETHING"; string password = "ELSE"; string usernamePassword = username + ":" + password; CredentialCache mycache = new CredentialCache(); mycache.Add(new Uri("WEB_URL"), "Basic", new NetworkCredential(username, password)); myReq.Credentials = mycache; myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword))); WebResponse wr = myReq.GetResponse(); Stream receiveStream = wr.GetResponseStream(); StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8); string content = reader.ReadToEnd();

所以,没有任何人有一个代码,XML文档发送到http服务,这部分我不知道怎么写,我不知道我是在写操作痕迹,我相信它有去somethig这样

So does anybody have a code to send XML document to http service, this part I don't know how to write, I don't know am I on the write trace, I belive it has to go somethig like this

request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded";

所以,普莱舍有人可以帮我! !谢谢

So plese can somebody help me! THANKS!

推荐答案

下面是我得到的,希望这是对你有用:

Here is something I get, hope it's useful to you:

HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("WEB_URL"); myReq.Method = "POST"; myReq.ContentType = "text/xml"; myReq.Timeout = 30000; myReq.Headers.Add("SOAPAction", ":\"#save\""); byte[] PostData = Encoding.UTF8.GetBytes(xmlDocument); myReq.ContentLength = PostData.Length; using (Stream requestStream = myReq.GetRequestStream()) { requestStream.Write(PostData, 0, PostData.Length); } HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();

更多推荐

使用Web服务的HTTP POST

本文发布于:2023-10-09 21:04:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476782.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Web   HTTP   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!