1. aruna bathan's Avatar
    Hi,
    I am new in windows mobile app development. I want to get http response from third party url(like API response). I tried all way but i didn't get any response its always return "Web Exception" , i am not able find the exact. Can anyone please help me.

    below my code

    [CODE]
    HttpWebRequest request_res = (HttpWebRequest)WebRequest.Create("http://google.com");
    request_res.Method = "GET";
    request_res.BeginGetResponse(new AsyncCallback(responseCallback) , request_res);

    private void responseCallback(IAsyncResult result) {
    try {
    HttpWebRequest request = (HttpWebRequest)result.AsyncState;
    HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
    TextReader reader = new StreamReader(response.GetResponseStream());
    string strResponse = reader.ReadToEnd();
    } catch (System.Net.WebException ex) {
    MessageBox.Show(ex.ToString());
    }

    }
    [/CODE]

    Regards,
    Arunabathan.G
    02-24-2014 07:49 AM
  2. Ray Adams's Avatar
    If you developing for Windows Phone 8 you better use Tasks.

    For example

    Code:
    HttpWebRequest req = WebRequest.CreateHttp(url);
    req.Method = "GET"; //get is default
    
    var tsk = Task.Factory.FromAsync<WebResponse>(req.BeginGetResponse, req.EndGetResponse, req);
    
    if (!tsk.Wait(60000))
                            {
                                throw new Exception("Timeout");
                            }
    
    HttpWebResponse resp = tsk.Result as HttpWebResponse;
    
    string body = "";
    
    using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
    {
       body = reader.ReadToEnd();
    }
    aruna bathan likes this.
    02-25-2014 12:54 PM
  3. Catholic Tech Geek's Avatar
    I would think that using WebClient would be a good option.
    aruna bathan likes this.
    02-26-2014 01:21 PM
  4. aruna bathan's Avatar
    Hi Ray Adams,
    Still i am getting the "Exception". Right now i am checking app with "Windows Phone Emulator". I want to get response from following url http://gzmo.co/yourls-api.php?signat...&format=simple.

    Regards,
    Arunabathan.G
    02-27-2014 03:11 AM
  5. polomint's Avatar
    What exactly are you passing? Are you passing the parameters correctly?
    I agree with TechGeek.. Use WebClient.
    02-27-2014 03:26 AM
  6. polomint's Avatar
    If i remember, i will check once i get home. I'm on court today so it may be a while lol
    02-27-2014 03:27 AM
  7. Ray Adams's Avatar
    Hi Ray Adams,
    Still i am getting the "Exception". Right now i am checking app with "Windows Phone Emulator". I want to get response from following url http://gzmo.co/yourls-api.php?signat...&format=simple.

    Regards,
    Arunabathan.G
    Can you open url in IE in emulator? May be you just have a problem with connection?
    02-27-2014 07:06 AM
  8. aruna bathan's Avatar
    Hi,
    Here is my answer.
    [CODE]
    WebClient webClient = new WebClient();
    webClient.DownloadStringAsync(new Uri(requestUrl));
    webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Detail_DownloadStringCompleted);


    private void Detail_DownloadStringCompleted(object sender , DownloadStringCompletedEventArgs e) {
    string responseTxt = e.Result.ToString().Trim();
    }
    [/CODE]

    Regards,
    Arunabathan.G
    03-03-2014 01:43 AM

Similar Threads

  1. why should i get xb1 to complete my MS ecosystem?
    By chrisevans937 in forum The Xbox Lounge
    Replies: 86
    Last Post: 06-19-2014, 01:17 AM
  2. Why does my Icon get hot?
    By DeathByPlant in forum Nokia Lumia Icon
    Replies: 10
    Last Post: 03-30-2014, 06:40 PM
  3. Can we still get GDR3 in developers preview?
    By Dantekai14 in forum Windows Phone 8
    Replies: 31
    Last Post: 03-02-2014, 02:45 AM
  4. Better WiFi connection after getting Black update
    By Kerry Andrews in forum Nokia Lumia 520
    Replies: 1
    Last Post: 02-24-2014, 07:05 AM
  5. Getting really bored now ....
    By davidD93 in forum Nokia Lumia 620
    Replies: 1
    Last Post: 02-23-2014, 10:50 AM
LINK TO POST COPIED TO CLIPBOARD