403 Forbidden from xively api SIM900 shield - gsm

I use SIM900 shield with arduino UNO. I try to make conection with xively server. I follow the instructions from: http://arduino.cc/en/Tutorial/GSMExamplesXivelyClient?from=Tutorial.GSMExamplesPachubeClient
This example is for other GSM shield, but it show me how should look like conection with xively. I've made such code:
gsm.SimpleWrite("PUT /v2/feeds/");
gsm.SimpleWrite(1055165076);
gsm.SimpleWriteln(".csv HTTP/1.1");
gsm.SimpleWrite("Host: api.xively.com\n");
gsm.SimpleWrite("X-ApiKey: ");
gsm.SimpleWriteln("j2AlGTCLxJzArQhL7dqrLYG6BtJd5aI8LoJmc7ha0mgsPWPD");
//gsm.SimpleWrite("User-Agent: ");
//gsm.SimpleWrite(arduino);
gsm.SimpleWrite("Content-Length: ");
gsm.SimpleWriteln(10);
gsm.SimpleWrite("Content-Type: text/csv\n");
gsm.SimpleWriteln("Connection: close");
gsm.SimpleWriteln("");
gsm.SimpleWrite("sensor1,");
gsm.SimpleWriteln(16);
gsm.SimpleWrite(end_c);
By this code I would like to send sensor1 value : 16.
After execution of this code xively server make my some answer:
HTTP/1.1 403 Forbidden
Date: Mon, 25 Nov 2013 08:19:27 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunkd
oncin ls
4
Yud o aetencesr emsin oacs hsrsuc
On web https://xively.com/dev/docs/api/communicating/http/http_status_codes/ i found that error mean:
403 Forbidden Xively understands your request, but refuses to fulfil it. An accompanying error message should explain why.(NOTE: in the V2 API, this is the error returned when the API rate limit is exceeded.)
If I change for example API-KEY, server give me 404 error. I'm trying to solve this problem for several days. Maybe someone has an idea what is wrong?

Try to add "Accept: */*"
I believe your Content-Length should be 11 (including newline).

Related

Arduino Esp8266 Response Timeout

I'm trying to test sending HTTP requests from my Arduino. I decided to use Free RESTful web service - http://services.groupkt.com. But something goes wrong and I don't understand what.
GET request:
GET /country/get/all HTTP/1.1
Host: 45.79.172.152
Connection: keep-alive
Serial Monitor:
AT+CIPMUX=0
OK
AT+CIPSTART="TCP","45.79.172.152",80
CONNECT
OK
AT+CIPSEND=74
OK
>
busy s...
Recv 74 bytes
SEND OK
+IPD,493:HTTP/1.1 408 Request Timeout
Date: Thu, 07 Jun 2018 16:10:59 GMT
Server: Apache/2.4.25 (Debian)
Content-Length: 307
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>408 Request Timeout</title>
</head><body>
<h1>Request Timeout</h1>
<p>Server timeout waiting for the HTTP request from the client.</p>
<hr>
<address>Apache/2.4.25 (Debian) Server at services.groupkt.com Port 80</address>
</body></html>
CLOSED
What I'm doing wrong?
HTTP is not like Telnet. You can't enter a HTTP request line by line in Serial Monitor.
HTTP requests are meant to be sent by a program and the timeout to receive the
complete request on servers is one or two seconds. Write a sketch the sends the request.

How can I access web site with ESP8266?

I'm trying to retrieve a HTTP resource (http://srcafe21.cafe24.com/mylight.php?id=2) using ESP8266:
ESP8266 AT commands :
AT+CWMODE=3
AT+RST
AT+CWJAP="iptime-3","20030214"
AT+CIFSR
AT+CIPMUX=0
AT+CIPSTART="TCP","srcafe21.cafe24.com",80
AT+CIPSEND=60
GET/HTTP/1.1
Host:srcafe21.cafe24.com/mylight.php?id=2
AT+CIPCLOSE
I get this response:
SEND OK +IPD,311:HTTP/1.1 400 Bad Request
Server: nginx Date: ....
What am I doing wrong?
Your use of HTTP is wrong. It should be
GET /mylight.php?id=2 HTTP/1.1
Host: srcafe21.cafe24.com

PUT http request query

Actually I am trying to send PUT request to a remote server the request is successfully send to the remote server but unfortunately the request is considered a bad request it can not see the body of the request I hope my discription is clear and here is the code for sending the request in Arduino programming language:
Serial.println("Sending to Server: ");
client.print("PUT /***/***/sensor/uod/1/A/1 HTTP/1.1\n");
Serial.print("PUT /***/***/sensor/uod/1/A/1 HTTP/1.1");
client.print("Host: ********.koding.io\n");
client.print("Cache-Control: no-cache\n");
client.print("Content-Type: application/x-www-form-urlencoded\r\n\r\n");
client.print("status=1");
one thing I want to mention that from the server side I used a tool that is called postman and from it it works successfully without any error and actually I have taken it's http request and convert it into the code to be send and you can find the http request below:
PUT /***/***/sensor/uod/1/A/1 HTTP/1.1
Host: *******.koding.io
Cache-Control: no-cache
Postman-Token: 8740ccb4-c0f2-a916-fd52-3089e4f3cbc9
Content-Type: application/x-www-form-urlencoded
status=0
I have solve the problem by adding content-Length: 10 header
Serial.println("Sending to Server: ");
client.print("PUT /***/***/sensor/uod/1/A/1 HTTP/1.1\n");
Serial.print("PUT /***/***/sensor/uod/1/A/1 HTTP/1.1");
client.print("Host: *********.koding.io\n");
client.print("Cache-Control: no-cache\n");
client.print("Content-Type: application/x-www-form-urlencoded\r\n");
client.print("Content-Length: 10\r\n\r\n");
client.print("status=1\r\n");

Arduino ESP8266 does not receive all data from HTTP server

I am using arduino and esp8266 to interact with my HTTP server(Nginx+flask). I have already successful sent the request to server, however, while I checked the message esp8266 received, the esp8266 did not get all data from server.
The supposed result should be:
+IPD,179:HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Sat, 02 Jan 2010 00:11:02 GMT
Content-Type: application/json
Content-Length: 25
Connection: keep-alive
{
"status": "SUCCESS"
}
and currently the result I got is:
+IPD,179:HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Sat,
The stream I sent to the ESP8266 module:
AT+CWMODE=1
AT+CWJAP="Telstra1357_2.4G","adelaide12345"
AT+CIPMUX=0
AT+CIPSTART="TCP","192.168.0.6",80
AT+CIPSEND=217 POST /data/push/ HTTP/1.1
Host: 192.168.0.6
User-Agent: Sensor Station
Content-Type: application/json
Content-Length: 89
{"device_id":0,"data":[{"label":"Light","reading":606}, {"label":"Motion","reading":497}]} `
I have tried to use timeout/delay to wait for more data, but it didnt work.
Anyone has same problem?
I had similar prolems! For me it helped checking the baud rate. I connected the ESP8266 with SoftwareSerial but the ESP worked on 115200 which is too high for SoftwareSerial. I changed the baud rate with AT+UART_DEF=9600,8,1,0,0 to 9600 and then it worked fine! You need to check your firmware to get the right AT- command.
Check your power supply (external power is most suitable) and send an CLOSE-command. It might help!

HTTP headers for chunked encoding POST - Error 411

I'm sending data to a server with an Arduino which requires constructing an HTML POST line-by-line. I don't necessarily know the Content-Length a-priori, so I am using "chunked" encoding.
When I tried this example post from Wikipedia with the "Transfer-Encoding" option as specified in rfc2616
client.println("POST /myurl HTTP/1.1");
client.println("Host: 12.345.679.999"); // replaced with the test server's IP
client.println("User-Agent: Arduino/1.0");
client.println("Transfer-Encoding: chunked");
client.println();
client.println("4");
client.println("test");
client.println("0");
client.println();
or, with escape characters explicit:
client.print("4\r\ntest\r\n0\r\n\r\n");
I receive the error from my server:
HTTP/1.1 411 Length Required
A request of the requested method POST requires a valid Content-length.
Server: Apache/2.2.22 (Ubuntu)
However, "chunked" encoding shouldn't require a Content-Length header field, see 4.4 - Message Length in rfc2616
Am I missing a field? Why doesn't this call work?
For the record, the non-Chunked-Encoding works:
if(client.connect(server, 80)){
String PostData = "test";
Serial.println("POST /myurl HTTP/1.1");
client.println("Host: 12.345.679.999"); // replaced with the test server's IP
Serial.println("User-Agent: Arduino/1.0");
Serial.print("Content-Length: ");
Serial.println(PostData.length());
Serial.println();
Serial.println(PostData);
}
UPDATE
From the apache2 error.log: "chunked Transfer-Encoding forbidden"
After finding
chunked Transfer-Encoding forbidden
in my Apache2 log I concluded that the error was not in the POST that I was making.
I found that modwsgi (the middle-layer between apache and django) does not enable chunked transfer-encoding by default. In the past, chunked wasn't supported at all
Refering to the change-log in the new version of modwsgi, I found that writing
WSGIChunkedRequest On
in my apache httpd.conf file allowed chunked requests (no more 411 error)

Resources