Cannot get/push data to Ubidot using bare-IP with DNSClient (SOLVED)

This topic continues from

I have a core that won’t resolve hostnames, so I implemented as suggested an external DNS client, which properly resolves to an IP address.

Now I’m revisiting Ubidot’s SparkCore example, below is my code:

#include "HttpClient/HttpClient.h"
#include "application.h"
#include "DNSClient.h"
HttpClient http;
#define TOKEN "XXX"
// Mockup variable
int ticker = 0;
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
      { "Content-Type",     "application/json" },
      { "X-Auth-Token" ,    TOKEN },
      { NULL, NULL } // NOTE: Always terminate headers will NULL
http_request_t request;
http_response_t response;
IPAddress dnsServerIP(8,8,8,8);
IPAddress remote_addr;
DNSClient dns;
char serverName[] = "";
void postData(void){
    request.body = '{\"value\":' + String(ticker) + "}";
    http.get(request, response, headers);
void setup() {
    // Initialize serial console
    // Initialize server information, get IP via DNS resolv
    request.port = 80;    
    dns.getHostByName(serverName, remote_addr);
    request.ip = remote_addr;
    request.path = "/api/v1.6/variables/"VARIABLE_ID"/values";

void loop() {
    static system_tick_t last = millis();
    if (millis() - last > 10000) {
        last = millis();

But the nginx server replies with the following:

HttpClient>     Connecting to IP:
HttpClient>     Start of HTTP Request.
POST /api/v1.6/variables/544fe7627625424c6a6abaf5/values HTTP/1.0
Connection: close
Content-Length: 13
Content-Type: application/json
X-Auth-Token: PuP02Cgumot6RYYOhBAlaSkSnFQO1YodBa8PAglfq5mMQ4g2ewZ8qU0p89uM
HttpClient>     End of HTTP Request.

HttpClient>     Receiving TCP transaction of 128 bytes.
HTTP/1.1 404 Not Found
Server: nginx
Date: Thu, 30 Oct 2014 21:39:49 GMT
Content-Type: text/html
Content-Length: 162
Connection: close
Vary: Accept-Encoding

<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>

HttpClient>     End of TCP transaction.

However when testing with the bare-resolved IP in my browser, it displays correctly. Yesterday the server also replied with the same “not found” 404 error code as above, but since my last mail with the Ubidots team, it seems they resolved this already today:

Vary: Accept
Content-Type: text/html; charset=utf-8

Is there any consideration or step I’m missing? does this also happened to anyone? I could not test my code with a SparkCore without the DNS issue.

Thanks, as always!


Hi @alinanco

Are you sending a “Host:” header? That is likely to be required since that hostname resolves to a host that is not unique (its canonical name is so the server can’t figure out which of the possible web servers that are hosted on this one physical server you might want if you don’t supply a “Host:” header. You can’t send a “Host:” header since that is ambiguous.

Crap! Yes, you are right, I missed including the host parameter into the header, now it works as expected.

Thanks @bko as always!


1 Like