Cannot get website content using HttpClient with my Meadow

Even if I’m connected to the WifiAdapter, I cannot get the content of a web site.
I always get a Timeout.

Btw: it is my own website, the content is very small (only one word), and the url is correct, I can get the content if I post the url in a browser. This works with https and http. I also tried some famous websites, but this does not work either. So I’m pretty sure that the that the website is accessible and that is not a SSL problem.

I tried it with a 5 min timeout, which didn’t make a difference.

I also tried the green code, which is comment out. That’s from the Getting Started pages. But this ends in the same behaviour: timeout.

Does someone have an idea what could be the problem and/or what I can try next?
Am I missing some necessary credentials for the HttpClient? But in the examples there are none, too.

Thanks in advance!

Could you file an issue in the Meadow_issues repository and also please add the application project to the issue. It looks like you are just using WiFi Basics and this is well tested on every release.

Regards,
Mark

@otto Can you share a zipped copy of your full project?

There are a lot of things that can cause errors in making network requests because of all the moving parts and prerequisites, so seeing the full project will make it easier to debug.

On my own setup, I was just able to make a successful call to both https://postman-echo.com/get?foo1=bar1&foo2=bar2 and my own blog at https://www.patridgedev.com.

Here are some things worth checking in your Meadow setup:

  • Have you configured your wifi connection SSID and password? This can be done either via code or via a wifi.config.yaml file.
  • Have you definitely connected to your wifi network? This can be done via code or via meadow.config.yaml using the Coprocessor > AutomaticallyStartNetwork: true setting.
  • Do you have the time on the Meadow set to something reasonable? If the time is not set or set too far in the past/future, SSL validation can definitely break. You can set this via code or via meadow.config.yaml using the Network > GetNetworkTimeAtStartup: true setting.

If anyone else wants to test the same code from the OP, here’s a copy-paste-friendly version.

public async Task GetWebPageViaHttpClient2(string uri)
{
    Console.WriteLine(string.Format("Starting to get {0}", uri));
    using HttpClient client = new HttpClient();
    client.Timeout = new TimeSpan(0, 1, 0);
    try
    {
        //HttpResponseMessage response = await client.GetAsync(uri);
        //Console.WriteLine(string.Format("Got response from {0}, Version={1}", uri, response. Version.ToString()));
        //response. Ensure SuccessStatusCode();
        //Console.WriteLine("SuccessStatusCode");
        //var responseBody = await response.Content.ReadAsStringAsync();
        //Console.WriteLine(string.Format("SUCCESS: {0} delivered \"{1}\"", uri, responseBody));
        var content = await client.GetStringAsync(uri);
        Console.WriteLine(string.Format("SUCCESS: {0} delivered \"{1}\"", uri, content));
    }
    catch (TaskCanceledException)
    {
        Console.WriteLine(string.Format("TIMEOUT: couldn't get {0}", uri));
    }
    catch (Exception ex)
    {
        Console.WriteLine(string.Format("EXCEPTION: couldn't get {0}, ex={1}", uri, ex.Message));
    }
}

Hello this is Gulshan Negi
Well, If you are attempting to retrieve the content of a website using HttpClient and run into timeouts, there are a few things you can look at and do to fix the problem:

  1. Verify that your device is connected to the internet and that the Wi-Fi connection is reliable to ensure network connectivity and stability.
  2. Make sure your network configuration permits outbound HTTP/HTTPS requests and look for any firewall or proxy settings that might be preventing the request.
  3. Confirm that your device is capable of resolving the domain name of the website you are attempting to access and that DNS resolution is operating properly.
    I hope you are clear now.
    Thanks

Thank you ALL for trying to help.

In the meantime I found the time to continue. Results:

  • sometimes it worked
  • sometimes not

I tried it with different target websites, within and out of my home network. I used different WLANs, and number IP address (192.168…) as well as DNS names. Http as well as https. I tried to place the meadow only within 5 meter distance of my router.
=> There is no pattern recognizable.

I suppose a hardware (or firmware?) problem with my meadow. I ordered some more meadows, but I haven’t received them yet, probably next week or so. Then I will test the same program with a different meadow to confirm or not to confirm this suspicion.