当前位置: 代码迷 >> ASP.NET >> asp.net 怎么调用http接口
  详细解决方案

asp.net 怎么调用http接口

热度:6103   发布时间:2013-02-26 00:00:00.0
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();
}
  相关解决方案