Note that there are some explanatory texts on larger screens.

plurals
  1. POAlternative to this Http Request
    primarykey
    data
    text
    <p>I have a class that goes and grabs some data and returns it as a string. While this object is working there is a spinning icon letting the user know work is being done. The problem is the code exits before the response comes back. I stuck a</p> <pre><code>while(response == null) </code></pre> <p>In just to see whats going on and the</p> <pre><code>response = (HttpWebResponse)request.EndGetResponse(AsyncResult); </code></pre> <p>is not firing. It fires ok in a console application so I am putting this down to something I am doing that silverlight doesn't like, heres the full code:</p> <pre><code>public class HttpWorker { private HttpWebRequest request; private HttpWebResponse response; private string responseAsString; private string url; public HttpWorker() { } public string ReadFromUrl(string Url) { url = Url; request = (HttpWebRequest)WebRequest.Create(url); request.CookieContainer = new CookieContainer(); request.AllowAutoRedirect = true; request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6"; AsyncRequest(); // The Demon! return responseAsString; } private void AsyncRequest() { request.BeginGetResponse(new AsyncCallback(FinaliseAsyncRequest), null); } private void FinaliseAsyncRequest(IAsyncResult AsyncResult) { response = (HttpWebResponse)request.EndGetResponse(AsyncResult); if (response.StatusCode == HttpStatusCode.OK) { // Create the stream, encoder and reader. Stream responseStream = response.GetResponseStream(); Encoding streamEncoder = Encoding.UTF8; StreamReader responseReader = new StreamReader(responseStream, streamEncoder); responseAsString = responseReader.ReadToEnd(); } else { throw new Exception(String.Format("Response Not Valid {0}", response.StatusCode)); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload