1

I'm trying really hard to use HttpClient lib in my project.

I can't figure out what's going on...

I tried local URLs, examples online, even on Xamarin.Forms pages and nothing. It just doesn't work and I can't figure out what am I doing wrong here.

This is code: (taken from here, btw: https://github.com/conceptdev/xamarin-forms-samples/blob/master/HttpClient/HttpClientDemo/Earthquake/GeoNamesWebService.cs)

enter image description here

The second breakpoint is never hit.

This is my references section:

enter image description here

I tried manually inserting the System.Net.Http like I saw in some examples, but it also doesn't work:

enter image description here

Any ideas?

EDIT

To add more information. If I use my local server and set a breakpoint there, it is never hit as well. It looks like the request never "leaves" the application. And I think this could be related to not being able to add System.Net.Http. But I don't know... It's really stressing me out...

Waiting to resolve:

enter image description here

Fiddler:

#   Result  Protocol    Host    URL Body    Caching Content-Type    Process Comments    Custom  
3675    200 HTTP    api.geonames.org    /earthquakesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=bertt  1,232   no-cache    application/json;charset=UTF-8  windowsformsapplication1.vshost:18544           

TARGET:

enter image description here

9
  • What happens if you replace 'var earthquakesJson = response.Content.ReadAsStringAsync().Result;' with 'var earthquakesJson = await response.Content.ReadAsStringAsync();' ? Commented Jul 12, 2016 at 12:35
  • @DimitrisTavlikos same thing, second BP is never hit. Please check my updated answer with the code. Commented Jul 12, 2016 at 12:38
  • Ok, I see your change, but why are you still trying to get the result with ".Result", instead of just await-ing? Commented Jul 12, 2016 at 12:45
  • @DimitrisTavlikos no reason, just some crazy tests I'm running trying to figure it out. But even if I do await return await earthquakesJson; it still never reaches the second BP. Commented Jul 12, 2016 at 12:48
  • Just tested your code and it works here. Xamarin Studio, Xamarin.Forms PCL on a Mac. I think you should check your PCL profile. Commented Jul 12, 2016 at 12:56

3 Answers 3

2

This is more troubleshooting at this point, because there are numerous things that could be going wrong.

  1. Download Fiddler, and try typing the url in yourself to see if you are receiving a response.

  2. Clean your solution, and rebuild.

Sign up to request clarification or add additional context in comments.

2 Comments

I did that and fiddler says it's returning the data. I've cleaned and rebuilt several times since yesterday and again now... do you have any ideas?
Thank you for referring to fiddler. It helped me figure out what was the issue. I still can't debug, but at least now I'm able to receive the data.
0

I would highly reccomend checking out Flurl instead of HTTPClient.

Here's the nuget package [here] (https://www.nuget.org/packages/Flurl.Http/)

and the link to the documentation

It's very simple to get your results and parsing them, especially with Json:

T poco = await "http://api.foo.com".GetJsonAsync<T>();

Comments

-1

Have you tried adding in the nuget component HttpClient from microsoft. You require this to work with PCLs

https://www.nuget.org/packages/Microsoft.Net.Http/

1 Comment

Yes, if you check my references section, the ...Primitives and ...Extensions come from that lib. Just System.Net.Http that doesn't show up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.