Client.connect() works with domains but not with local ip [SOLVED]

Hi Spark Community!

I have a strange issue, when i connect to an internet based domain, i can send the GET command to the server, but if i’m sending the same package to a local server (on a local network), it is not sending the package.

Does the core have any limitation for local networks?

Here is my code (if i replace byte server[] with a public ip on the internet and the Host: with it’s host, it works like a charm, but not this ip based solution on the local network is not working). I have no clue why :frowning:

Any help would be appreciated.

byte server[] = { 192,168,0,104 };

String data;

client.connect(server, 80);
client.print("GET /target.cgi?a=test");
client.println(" HTTP/1.1");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Connection: close");
client.print("Content-Length: ");

Hi @Noten

Did you mean GET or POST. I am confused by the x-www-form-urlencoded and the data being sent. It looks more like a POST request.

hi @bko!

Actually it doesn’t matter, because it is not calling the file at all. I added on the server a script that even if the file is being called (regardless of the variables), a file will be updated. But that is not happening at all :frowning:

What I would try to debug this is to use another computer on the same local network and try to do your GET request with curl -v and see what is happening.

hi @bko!

I tried that already and that works. Also if i directly call the url from a browser (…)

At the moment if i write the code to use a public domain with a public ip, the code starts working. But it’s not working on the local environment.

I have no idea what is this.

Is there any other way to send data from the core to a webserver?

I tried to do something with the HttpClient library, but that generates error for me, so i’m stuck :frowning:

Hi @Noten

When you tried curl to the local host, did you use the -v flag and look at the headers and output?

Can you ping the server from your core?

//Should print 5 meaning 5 successful pings

hi @bko!

Yes, everything looks okay for the curl.

I tried the ping as well, and it returns 5.

Okay, this is strange, i just installed a MAMP server for my mac, and for this it works properly.

If i try it with another machine (lighttpd) on the same network, it is not working.

I’m not a pro on server settings, but i guess this will be something on the server side.

The only difference is that in the working case both machines are on Wifi, while it is not working with the spark (wifi) and the machine which is on cable to the same router.

Can it be some routing issue between the machine on wifi and cable?

It’s probably not a cabling vs wifi routing issue, and more likely a server config issue.

Can you change the “GET” to “POST” in your request? It could be confusing lighttpd. I’m not sure how robust lighttpd is versus Apache in its willingness to accept unusual requests.

If that doesn’t work, try doing a plain “GET” request like this. Start with something super simple and go from there.

byte server[] = { 192,168,0,104 };

client.connect(server, 80);
client.print("GET /target.cgi?a=test HTTP/1.1");
client.println("Connection: close");
client.print("Content-Length: 0");

Thank you guys, found the solution!

I uninstalled lighttpd and tried apache instead and it works properly with apache.

My guess is something in the headers was choking up lighttpd. It could also be that some delay()s or a client.flush() was needed. As robust as many of them are, web servers can still be cantankerous!