How can I access web site with ESP8266? - http

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

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.

POST api Rest with AT Commands - SIM800

I'm having problems sending post parameters over a SIM800 module using AT. For while I'm using FTDI and mac screen application terminal.
Here is my command sequence:
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","myhost/deviceRegister"
AT+HTTPPARA="CONTENT","application/json"
AT+HTTPDATA=94,120000
OK
DOWNLOAD
POST deviceRegister HTTP/1.1
Host: myhost
Content-Length:13
{"IMEI":"aa"}
AT+HTTPACTION=1
AT+HTTPREAD
Until here, everything looks fine, but when I log my post request in my server what I have is this:
+HTTPREAD: 259
POST deviceRegister HTTP/1.1
Host: myhost
Accept: */*
Connection: Keep-Alive
Content-Type: application/json
User-Agent: SIMCOM_MODULE
Content-Length: 94
{"IMEI":"aa"}gister HTTP/1.1
OK
It looks like it is posting to the body without \n
Why my post body has headers parameters ?
That s what i tried on my sim900 modem
{"myvar1="myvalue1","myvar2"="myvalue2"} is my json object
AT+CGATT?
AT+SAPBR=3,1,"CONTYPE","GPRS"
AT+SAPBR=3,1,"APN","mynetworkprovider.com"
AT+SAPBR=3,1,"USER","mylogin"
AT+SAPBR=3,1,"PWD","mypassword"
AT+SAPBR=1,1
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://myserveraddress/comm.php"
AT+HTTPPARA="CONTENT","application/json"
AT+HTTPDATA=137,5000 **=>SIM response : DOWNLOAD**
Content-Length: 414
{"myvar1="myvalue1","myvar2"="myvalue2"}
AT+HTTPACTION=1
AT+HTTPREAD =>should respond 200 http ok status
hth
I m not an expert but on my sim900 modem i tried this and it works for me
AT commands to initialize Modem for data transfert
and
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","myhost/deviceRegister"
AT+HTTPPARA="CONTENT","application/json"
AT+HTTPDATA=94,120000
OK
DOWNLOAD
Content-Length:13
{"IMEI":"aa"}
AT+HTTPACTION=1
AT+HTTPREAD
Hope this help

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");

RabbitMQ WebSocket 404 Not Found

I'm running rabbitmq-server v3.3.5-1.1 on the Debian v8.2. I have enabled rabbitmq_web_stomp and rabbitmq_web_stomp_examples as per suggestion in the docs:
rabbitmq-plugins enable rabbitmq_web_stomp
rabbitmq-plugins enable rabbitmq_web_stomp_examples
All examples exposed at http://127.0.0.1:15670 work as intended, but they all use SockJS rather than native browser's WebSocket:
// Stomp.js boilerplate
var ws = new SockJS('http://' + window.location.hostname + ':15674/stomp');
var client = Stomp.over(ws);
I would like to stick to the WebSocket so I tried what was suggested in the docs:
var ws = new WebSocket('ws://127.0.0.1:15674/ws');
This throws an error to my face:
WebSocket connection to 'ws://127.0.0.1:15674/ws' failed: Error during WebSocket handshake: Unexpected response code: 404
Further tests with netcat confirm 404:
# netcat -nv 127.0.0.1 15674
127.0.0.1 15674 open
GET /ws HTTP/1.1
Host: 127.0.0.1
HTTP/1.1 404 Not Found
Connection: close
Content-Length: 0
Date: Sat, 23 Jan 2016 20:15:13 GMT
Server: Cowboy
Obviously cowboy does not expose /ws path, so I wonder:
Is it possible to reconfigure cowboy in this situation? How? Is it worth it?
May I use nginx in the place of the cowboy (preferred option)? How?
What other options do I have?
EDIT
RabbitMQ docs are misleading. Correct WebSocket URI:
http://127.0.0.1:15674/stomp/websocket
good job, but:
new WebSocket('http://127.0.0.1:15674/stomp/websocket')
VM98:2 Uncaught DOMException: Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. 'http' is not allowed.(…)(anonymous function) ...
need to use ws/wss-schema:
new WebSocket('ws://127.0.0.1:15674/stomp/websocket')
WebSocket {url: "ws://127.0.0.1:15674/stomp/websocket", readyState: 0, bufferedAmount: 0, onopen: null, onerror: null…}

Unable to test HTTP PUT-based file upload via Squid Proxy

I can upload a file to my Apache web server using Curl just fine:
echo "[$(date)] file contents." | curl -T - http://WEB-SERVER/upload/sample.put
However, if I put a Squid proxy server in between, then I am not able to:
echo "[$(date)] file contents." | curl -x http://SQUID-PROXY:3128 -T - http://WEB-SERVER/upload/sample.put
Curl reports the following error:
Note: This error response was in HTML format, but I've removed the tags for ease of reading.
ERROR: The requested URL could not be retrieved
ERROR
The requested URL could not be retrieved
While trying to retrieve the URL:
http://WEB-SERVER/upload/sample.put
The following error was encountered:
Unsupported Request Method and Protocol
Squid does not support all request methods for all access protocols.
For example, you can not POST a Gopher request.
Your cache administrator is root.
My squid.conf doesn't seem to be having any ACL/rule that should disallow based on the src or dst IP addresses, or the protocol, or the HTTP method... as I can do an HTTP POST just fine between the same client and the web server, with the same proxy sitting in between.
In case of the failing HTTP PUT case, to see the request and response traffic that was actually occurring, I placed a netcat process in between Curl and Squid, and this is what I saw:
Request:
PUT http://WEB-SERVER/upload/sample.put HTTP/1.1
User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Host: WEB-SERVER
Pragma: no-cache
Accept: */*
Proxy-Connection: Keep-Alive
Transfer-Encoding: chunked
Expect: 100-continue
Response:
HTTP/1.0 501 Not Implemented
Server: squid/2.6.STABLE21
Date: Sun, 13 May 2012 02:11:39 GMT
Content-Type: text/html
Content-Length: 1078
Expires: Sun, 13 May 2012 02:11:39 GMT
X-Squid-Error: ERR_UNSUP_REQ 0
X-Cache: MISS from SQUID-PROXY-FQDN
X-Cache-Lookup: NONE from SQUID-PROXY-FQDN:3128
Via: 1.0 SQUID-PROXY-FQDN:3128 (squid/2.6.STABLE21)
Proxy-Connection: close
<SNIPPED the HTML error response already shown earlier above>
Note: I have anonymized the IP addresses and server names throughout for readability reasons.
Thanks to Amos Jeffries for answering this on squid-users forum. The issue is basically that Squid before version 3.1 does not implement HTTP 1.1 and thus rejects the chunked transfer encoding.

Resources