Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

WP8/Android/IOS HttpRequest GetRequestStreamAsync never returns

$
0
0

I am trying to call makeRequestNotRight from iOS, Android and WP8 and doesn't work, but this very same code works fine when running in Windows directly. It just hangs and never returns a result. i can't figure out what is wrong.

string res = Voice.makeRequestNotRight("http://www.google.com", null) ;
public static CookieContainer cookiejar = new CookieContainer();
private static object makeRequestNotRight(string page, object data)
{


  Debug.WriteLine("request:" + page);

  string url = "";
  url = page;

  try
  {

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

    request.UserAgent = @"my app / 0.1";
    request.CookieContainer = cookiejar;

    request.Method = "GET";

    Task<WebResponse> responseTask = Task.Run(() => request.GetResponseAsync());

    Task.WaitAny(new Task[] { responseTask });
    WebResponse response = responseTask.Result;
    if (request.CookieContainer != null)
    {
      cookiejar = request.CookieContainer;
    }

    Stream s = response.GetResponseStream();

    using (StreamReader reader = new StreamReader(s, Encoding.UTF8))
      return reader.ReadToEnd();


  }
  catch (Exception ex)
  {
    throw new Exception(ex.Message);
  }
}

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>