是否可以使用asp.net页面将服务器的get结果作为XML文件发回?

时间:2010-05-28 06:58:44

标签: asp.net

我的应用程序通过Mblox XML接口发送SMS请求,我得到了Mblox作为XML文件的响应。

string RequestXML = GenerateRequestXML();

string uri = string.Empty; uri = "http://xml.us.mblox.com:8180/send"; 

HttpWebRequest request =(HttpWebRequest)WebRequest.Create(uri);

request.KeepAlive = false; 

request.ProtocolVersion = HttpVersion.Version11; 

request.Method = "POST";

request.ContentType = "text/xml";
HttpWebResponse respon = (HttpWebResponse)request.GetResponse()

1 个答案:

答案 0 :(得分:1)

你几乎就在那里......你已经有了响应,只需获得对ResponseStream的引用并读取返回的XML:

HttpWebResponse respon = (HttpWebResponse)request.GetResponse();
Stream receiveStream =    request.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
// Pipes the stream to a higher level stream reader with the required encoding format. 
StreamReader readStream = new StreamReader( receiveStream, encode );
//now you should be able to use readStream to get your XML. That's your homework.

See a complete example here