首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

asp.net 怎么调用http接口

2012-01-20 
asp.net 如何调用http接口asp.net采用post传递数据到远程其他系统的http接口。[解决办法]msdn searchhttpwe

asp.net 如何调用http接口
asp.net采用post传递数据到远程其他系统的http接口。

[解决办法]
msdn search

httpwebrequest

[解决办法]
HttpWebRequest
[解决办法]
WebRequest req = null;
WebResponse rsp = null;
try
{

string uri = "http://xxx ";
req = WebRequest.Create(uri);
//req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy
req.Method = "POST "; // Post method
req.ContentType = "text/xml "; // content type
// Wrap the request stream with a text-based writer
StreamWriter writer = new StreamWriter(req.GetRequestStream());
// Write the xml text into the stream
writer.WriteLine( "ASDFASD ");
writer.Close();
// Send the data to the webserver
rsp = req.GetResponse();

}
catch(WebException webEx)
{
string dd=webEx.Message;
}
catch(Exception ex)
{
string dd=ex.Message;
}
finally
{
if(req != null) req.GetRequestStream().Close();
if(rsp != null) rsp.GetResponseStream().Close();
}

热点排行