eestein
eestein

Reputation: 5104

Cannot get HttpClient working with PCL

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

Upvotes: 1

Views: 454

Answers (3)

Ravi L
Ravi L

Reputation: 1230

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>();

Upvotes: 0

Chris Clark
Chris Clark

Reputation: 397

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.

Upvotes: 2

Kym Phillpotts
Kym Phillpotts

Reputation: 149

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/

Upvotes: -1

Related Questions