问题
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!
回答1:
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
}
来源:https://stackoverflow.com/questions/4633132/httprequest-httpresponse-send-get-through-stream-and-receive-the-result-in-c-s