java - Call REST Service with c, Connectivity via a GSM Modem - HTTP/1.1 505 -


i have rest web service follows spring mvc , deployed tomcat-7.0.50 want call service through embedded code in micro controller device. gsm modem hosted device establish connectivity via gprs.

here sample c code using call rest service deployed in tomcat server.

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 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 data come _delay_ms(5000); printf(modem_buf); send_command("at+cipclose\r");  _delay_ms(5000); printf(modem_buf);   // check if in buffer  return modem_buf; } 

web service hosted under url http://10.8.155.16:8080/myservice (the ip 10.8.155.16 sample 1 , not actual 1 using, can connect tomcat server)

here code of rest service.

@requestmapping(value = "/addnums", method = requestmethod.post, headers = "accept=text/html") public @responsebody string addnumbers(@requestbody string request) {     try{      system.out.println("just enter addnums.... " + request);      int sum = 0;     list<string> values = arrays.aslist(request.split(","));     (string s : values) {         sum = sum + integer.parseint(s);     }     string sumasstring = integer.tostring(sum);     system.out.println("going send response");     return sumasstring;     }catch(exception e){         system.out.println("exception occured while processing..."+e.getmessage());         return "error";     } } 

but when call getting 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 

kindly assist me identify root course.

we able find answer own question , posting may helps else.

we able catch request via separate tcp server program , while debug request line saw device adding \r before each \n. string has \r\r\n such occurrences. reason program not work. when change string removing \r resolved problem.

    // send web request webserver     fprintf(&modem,"post /myservice/addnums http/1.1\n\     host: 10.8.155.16:8080\n\     content-type: text/html\n\     content-length:6\n\n\     10,100\     %c",26); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -