5 Replies - 5958 Views - Last Post: 14 May 2013 - 02:07 PM

#1 fran101  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 01-December 08

I cannot seem to get anything back when using httpWebResponse

Posted 25 March 2013 - 07:27 PM

I am using the following code:
    var request = (HttpWebRequest)WebRequest.Create(new Uri(addy));
            request.UserAgent = "Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))";
            request.BeginGetResponse(r =>
                                    {
                                        var httpRequest = (HttpWebRequest)r.AsyncState;
                                        var httpResponse = (HttpWebResponse)httpRequest.EndGetResponse(r);

                                        using (var reader = new StreamReader(httpResponse.GetResponseStream()))
                                        {
                                            var response = reader.ReadToEnd();
                                            results = (String)response;
                                        }
                                    }, request);



addy is: http://maps.googleap...dy&sensor=false

and results is just a global string to which I want to output the results of the web request.

The problem is just that I keep getting a null value output to results and I have checked the web address and it is correct and should have output.

Any ideas on this or if you can point me in the right direction i'd be grateful

Is This A Good Question/Topic? 0
  • +

Replies To: I cannot seem to get anything back when using httpWebResponse

#2 Takk  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 111
  • Joined: 08-March 13

Re: I cannot seem to get anything back when using httpWebResponse

Posted 25 March 2013 - 08:30 PM

You actually wont be able to make a call to another domain using the httpwebrequest method, do a search for 'JSONP' it should turn up some info which will be helpful to you.
Was This Post Helpful? -1
  • +
  • -

#3 fran101  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 01-December 08

Re: I cannot seem to get anything back when using httpWebResponse

Posted 26 March 2013 - 02:12 AM

View PostTakk, on 25 March 2013 - 08:30 PM, said:

You actually wont be able to make a call to another domain using the httpwebrequest method, do a search for 'JSONP' it should turn up some info which will be helpful to you.


I have tried using JSON also and still have not been sucessful, maybe you could point me to a example of JSON being implemented on windows phone 7 that would solve my problem above?
Was This Post Helpful? 0
  • +
  • -

#4 Takk  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 111
  • Joined: 08-March 13

Re: I cannot seem to get anything back when using httpWebResponse

Posted 26 March 2013 - 05:22 AM

Not JSON, but JSONP. you'll actually use the script tag in your html and a callback javascript function to grab the data, the script tag CAN reference other domains whereas httprequest cannot.

And paying more attention to whats actually going on here, you're using c#, not JS, soo...

http://www.csharp-ex...download-files/ <- that method will work a bit better in this situation
Was This Post Helpful? 1
  • +
  • -

#5 fran101  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 01-December 08

Re: I cannot seem to get anything back when using httpWebResponse

Posted 29 March 2013 - 04:58 AM

Thanks for the reply, I managed to sort the problem using the code below

WebClient webClient = new WebClient();
            webClient.OpenReadAsync(new Uri(addy));
            webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
            
        }

        void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            var reader = new StreamReader(e.Result);
            reader.ReadToEnd();
        }

Was This Post Helpful? 0
  • +
  • -

#6 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: I cannot seem to get anything back when using httpWebResponse

Posted 14 May 2013 - 02:07 PM

View PostTakk, on 26 March 2013 - 06:30 AM, said:

You actually wont be able to make a call to another domain using the httpwebrequest method, do a search for 'JSONP' it should turn up some info which will be helpful to you.


You can make requests to any domains through HttpWebRequest. There is no reason you wouldn't, unless the server has some restrictions.

By using the WebClient class, be aware that it is not the recommended approach - it runs on the UI thread and can cause unnecessary overhead there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1