问题描述
这就是我要做的:
-
连接到HTTP服务
-
从这里开始,我需要与该流相处.
-
现在,我发送了获取请求,服务回答我.
-
然后,在第一次获得请求和答案之后,我需要每次服务时都会拦截一些东西.
我该怎么办?
我昨天从Httrequest,httresponse,getResponsestream等尝试,但不起作用:(
如何让流来与服务发送get请求的服务?
netcf 3.5.
非常感谢!
推荐答案
这是如何同步
的示例WebRequest request = WebRequest.Create(url); request.Method = "GET"; request.ContentType = "text/html"; Stream reader = request.GetResponse().GetResponseStream();
和这里的异步样品
///........ WebRequest request = WebRequest.Create(url); request.Method = "GET"; request.ContentType = "text/html"; IAsyncResult result = request.BeginGetResponse(RequestCallback, request); ///........ private void RequestCallback(IAsyncResult ar) { var request = ar.AsyncState as WebRequest; Stream reader = request.EndGetResponse(ar).GetResponseStream(); //use this reader to read the content }
问题描述
This is what i'm trying to do:
Connect to a http service
From here, i need to get a STREAM for comunicate with that.
Now, i send GET request, and the service answer me.
Then, after the first GET request and the answer, i need to intercept everytime the service send me something.
How can i do?
I'm trying from yesterday with httRequest, httResponse, GetResponseStream and so on, but not working :(
How can i have the stream to "talk" with the service sending the GET request?
all this for NETCF 3.5.
Thanks a lot!
推荐答案
Here is a sample of how to do it synchronously
WebRequest request = WebRequest.Create(url); request.Method = "GET"; request.ContentType = "text/html"; Stream reader = request.GetResponse().GetResponseStream();
and here an asynchronous sample
///........ WebRequest request = WebRequest.Create(url); request.Method = "GET"; request.ContentType = "text/html"; IAsyncResult result = request.BeginGetResponse(RequestCallback, request); ///........ private void RequestCallback(IAsyncResult ar) { var request = ar.AsyncState as WebRequest; Stream reader = request.EndGetResponse(ar).GetResponseStream(); //use this reader to read the content }