HTTPS GET Request to import.io API - Server is not returning
Posted: Thu Sep 17, 2015 10:54 am
So. To make it short, i have following REST API URL from import.io (example):
https://api.import.io/store/data/45a41a ... cErQ%3D%3D
pasting this into my browser returns something.
Now i want that something on my arduino. So i thoght i'd just make a regular GET Request.
Problem is, i don't get anything back from the server. I tried Port 80 and 443 (http and https) and all possible ways of spelling the GET request out (With https://..., without, etc.). I'm not even getting a 400 back, i just get back nothing.
So, what am I probably doing wrong? Anyone out there able to get this to work or point me in the right direction? Can't be that hard, can it?
Here is my code
Some information before you ask: I can do GET request to the data.sparkfun.com server and receive data from them (either 200 or 400 if i did something wrong)
https://api.import.io/store/data/45a41a ... cErQ%3D%3D
pasting this into my browser returns something.
Now i want that something on my arduino. So i thoght i'd just make a regular GET Request.
Problem is, i don't get anything back from the server. I tried Port 80 and 443 (http and https) and all possible ways of spelling the GET request out (With https://..., without, etc.). I'm not even getting a 400 back, i just get back nothing.
So, what am I probably doing wrong? Anyone out there able to get this to work or point me in the right direction? Can't be that hard, can it?
Here is my code
Code: Select all
/*
* This sketch sends data via HTTP GET requests to data.sparkfun.com service.
*
* You need to get GUID and privateKey at data.sparkfun.com and paste them
* below. Or just customize this script to talk to other HTTP servers.
*
*/
#include <ESP8266WiFi.h>
const char* ssid = "------";
const char* password = "----";
const char* host = "api.import.io";
const char* import_url = "https://api.import.io/store/data/45a41a18-7c02-4b95-bcce-9506cabc2459/_query?input/webpage/url=http%3A%2F%2Fwww.ikea.com%2Fus%2Fen%2Fsearch%2F%3Fquery%3Dchair&_user=315f6e84-8fd6-449f-ae60-6eccfb9a017e&_apikey=7C2or4Abyj9Hhk%2BzDPQtDcwby5szRxJksOQk2qy%2FrJkvA1F7C82JG2WcDII3ofwuip3BK16Y8JLShCxwHgcErQ%3D%3D";
void setup() {
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(5000);
++value;
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 443;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = import_url;
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
Serial.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(10);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
Some information before you ask: I can do GET request to the data.sparkfun.com server and receive data from them (either 200 or 400 if i did something wrong)