基于Django的应用程序在heroku上显示错误HTTP / 1.1 505 HTTP版本不受支持

时间:2015-04-24 09:17:58

标签: heroku arduino django-rest-framework gsm arduino-due

我需要将一些数据从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系统发送测试了网络应用程序,下面的工作是详细信息

   $ 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'}}
   >>> 

请求我提供解决此问题的建议或帮助

1 个答案:

答案 0 :(得分:1)

解决了问题,问题在于" Content-Length"在HTTP标头中。它需要转换为ASCII。还有" / api / sprints HTTP / 1.1 \ r \ n"中双倍空格的拼写错误会导致同样的问题。 :)

经过19个小时的连续编码,我很愚蠢地犯了愚蠢的错误。