我需要将一些数据从 arduino 发送到基于休息的 Web 应用程序。
为了测试,我在 heroku 上创建了一个基于 django 的 Web 应用程序
现在,当我尝试使用 GSM AT 命令从 arduino 发送数据时,它显示以下错误
HTTP/1.1 505 HTTP Version Not Supported
Connection: close
Server: Cowboy
下面是我在arduino中的代码
const char HTTP_HEADER_POST[ ] = "POST /api/sprints HTTP/1.1\r\nHost: obttracker.herokuapp.com\r\nContent-Length: 54\r\n\r\nUser-Agent: obttracker\r\nConnection: keep-alive\r\nContent-Type: application/x-wwww-form-urlencoded\r\nAuthorization: Basic ZGVtbzpkZW1v\r\n\r\n"; //HTTP header line before length
const char HTTP_BODY_POST[] = "end=2015-05-19&name=TESTING&point=POINT%2834.2+45.3%29";
int tmp_post_len = strlen(HTTP_HEADER_POST);
//sending header packet to remote host
gsm_port.print("AT+QISEND=");
gsm_port.print(tmp_post_len);
gsm_port.print("\r");
delay(500);
gsm_get_reply();
//sending header
gsm_port.print(HTTP_HEADER_POST);
delay(500);
gsm_get_reply();
//validate header delivery
gsm_validate_tcp();
// send the body data
int body_len = strlen(HTTP_BODY_POST);
gsm_port.print("AT+QISEND=");
gsm_port.print(body_len);
gsm_port.print("\r");
delay(500);
gsm_get_reply();
gsm_port.print(HTTP_BODY_POST);
delay(500);
gsm_get_reply();
//validate previous transmission
gsm_validate_tcp();
parse_receive_reply();
我已经通过使用 python 请求通过我的 linux 系统发送测试了 web 应用程序,它的工作如下是详细信息
$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> import requests
>>> import pprint
>>> today = datetime.date.today()
>>> data = {'name': 'TESTSTING', 'end': today, 'point': 'POINT(56.3 33.3)'}
>>> resp = requests.get('http://obttracker.herokuapp.com/api')
>>> resp.status_code
200
>>> api = resp.json()
>>> pprint.pprint(api)
{u'sprints': u'http://obttracker.herokuapp.com/api/sprints'}
>>> resp = requests.post(api['sprints'], data=data, auth=('demo', 'demo'))
>>> resp.status_code
201
>>> sprint = resp.json()
>>> pprint.pprint(sprint)
{u'end': u'2015-04-24',
u'id': 3,
u'links': {u'self': u'http://obttracker.herokuapp.com/api/sprints/3'},
u'name': u'TESTSTING',
u'point': {u'coordinates': [56.3, 33.3], u'type': u'Point'}}
>>>
请求向我提供解决此问题的建议或帮助