开发者

How to Post XML data to a Web Service in MVC

开发者 https://www.devze.com 2022-12-17 23:38 出处:网络
I am very confused on this topic. I have a webservice on another machine. All I need to do is post the xml to the url and return the results to the view. I have not found any working examples of this.

I am very confused on this topic. I have a webservice on another machine. All I need to do is post the xml to the url and return the results to the view. I have not found any working examples of this. Also there seems to be different ways of doing it.

What is the best way to post xml data to a url and display the results in a vi开发者_高级运维ew?

Thanks


In the controller you could make a web request. Is this what you are looking for?

byte[] postData;

//set postData

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://another-server/service/");
request.Method = "POST";
request.ContentType="application/x-www-form-urlencoded";
request.ContentLength = postData.Length;

Stream response=request.GetRequestStream();
response.Write(postData,0,postData.Length);
response.Close();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号