通过GSM调制解调器HTTP/1.1505连接的带c的java Call REST服务
我有一个RESTWeb服务,它遵循SpringMVC,并与Tomcat-7.0.50一起部署 现在我想通过微控制器设备中的嵌入式代码调用该服务。GSM调制解调器托管在设备上,通过GPRS建立连接
下面是用于调用部署在tomcat服务器中的REST服务的示例C代码
char* connect_GPRS(void)
{
int cnt=0;
printf("connecting GPRS");
send_command("AT\r");
send_command("AT+CIPCLOSE\r");
send_command("AT+CIPSHUT\r");
send_command("AT+CIPCSGP=1,\"dialoguomlab\"\r");
send_command("AT+CGATT=1\r");
send_command("AT+CIPMODE=0\r");
send_command("AT+CIPSTART=\"TCP\",\"10.8.155.16\",\"8080\"\r"); // connect TCP
_delay_ms(1000);
send_command("AT+CIPSEND\r");
while ((strchr(modem_buf,'>')==NULL)&&(cnt<60)) //wait
{_delay_ms(100); cnt++; }
clr_buf();
// send web request to the webserver
fprintf(&modem,"POST /MyService/addnums HTTP/1.1\r\n\
Host: 10.8.155.16:8080\r\n\
Content-Type: text/html\r\n\
Content-length:6\r\n\r\n\
10,100\
%c",26);
while(modem_buf[0]==0); // wait for any data to come
_delay_ms(5000);
printf(modem_buf);
send_command("AT+CIPCLOSE\r");
_delay_ms(5000);
printf(modem_buf); // check if anything in the buffer
return modem_buf;
}
Web服务托管在urlhttp://10.8.155.16:8080/MyService
下
(ip 10.8.155.16只是一个示例,而不是实际使用的,我们可以连接tomcat服务器)
这是REST服务的代码
@RequestMapping(value = "/addnums", method = RequestMethod.POST, headers = "Accept=text/html")
public @ResponseBody
String addNumbers(@RequestBody String request) {
try{
System.out.println("just enter to addnums.... " + request);
int sum = 0;
List<String> values = Arrays.asList(request.split(","));
for (String s : values) {
sum = sum + Integer.parseInt(s);
}
String sumAsString = Integer.toString(sum);
System.out.println("going to send the response");
return sumAsString;
}catch(Exception e){
System.out.println("Exception occured while processing..."+e.getMessage());
return "Error";
}
}
但是当我们要求这样做时,我们得到了错误
HTTP/1.1 505 HTTP Version Not Supported Server: Apache-Coyote/1.1 Date: Fri, 27 Jun 2014 04:45:27 GMT Connection: close
请帮助我确定根课程
# 1 楼答案
我们能够找到我自己问题的答案,并发布帖子,因为这可能会帮助其他人
我们能够通过单独的TCP服务器程序跟踪请求,并且在调试请求行时,我们看到设备在每个请求行之前\r\n添加了另一个请求行。然后,该字符串对所有此类事件都具有\r\r\n。这就是该项目不起作用的原因。因此,当更改字符串时,通过删除\r解决了问题