HttpWebRequest and HttpWebResponse in C#

给你一囗甜甜゛ 提交于 2020-01-06 11:48:55

问题


How to use HttpWebRequest and HttpWebResponse to create a webservice and how will the request and responses will be send across the wire?


回答1:


this is the syntax for using HttpWebRequest and HttpWebResponse

WebRequest _request;
string text;
string url = "UrlToGet";
_request = (HttpWebRequest)WebRequest.Create(url);
using (WebResponse response = _request.GetResponse())
{
    using (StreamReader reader =new StreamReader(response.GetResponseStream()))
    {
         text = reader.ReadToEnd();
    }
}



回答2:


HttpWebRequest and HttpWebResponse are intended for client applications to make HTTP requests and read HTTP responses. You can't use them to create a server application.

If you want to create and consume SOAP web services using .NET then you need to learn WCF:

Windows Communication Foundation

WCF is a complex topic but Microsoft still support the legacy "ASP.NET Web Services" technology which might be easier to get a handle on to begin with:

ASP.NET Web Services

In particular:

XML Web Services Using ASP.NET



来源:https://stackoverflow.com/questions/6723792/httpwebrequest-and-httpwebresponse-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!