HTTP request error code
Answer
11/16/16 2:59 PM

Dear community users,

we are trying to share as much information as possible in case anybody faces a similar issue.

A user has an issue with an HTTP request:

I am now able to receive sensor data from other nodes on my xdk's.
But i have still some small bugs.
What is a perfect HTTP request answer that the XDK will need and not see a retcode other than zero ?
At the moment i have still a retcode 1309 - but i see the correct data.
How can i get rid of this - where can i see easy a failure text belonging to a retcode ?

 

 INFO | XDK DEVICE 1: [x] Bosch XDK - initialization WiFi ...
 INFO | XDK DEVICE 1: [x] Bosch XDK - a WiFi IP was retrieved : 192.168.178.148 OK
INFO | XDK DEVICE 1: [x] Bosch XDK - initialization HTTP REST Client ...
INFO | XDK DEVICE 1: [x] Bosch XDK - HTTP REST Client running ...
INFO | XDK DEVICE 1: sensor reading = 1
INFO | XDK DEVICE 1: now calling demo http_request site http://23.22.14.18:80/ip ...
INFO | XDK DEVICE 1: retcode_status=0
INFO | XDK DEVICE 1: now reading the response...
INFO | XDK DEVICE 1: len=33
INFO | XDK DEVICE 1: HTTP RESPONSE: 200 [application/json]
INFO | XDK DEVICE 1: {
INFO | XDK DEVICE 1:   "origin": "79.251.254.112"
INFO | XDK DEVICE 1: }
INFO | XDK DEVICE 1: now calling RedBearDuo5 ...
INFO | XDK DEVICE 1: retcode_status=1309
INFO | XDK DEVICE 1: now reading the response...
INFO | XDK DEVICE 1: len=24
INFO | XDK DEVICE 1: HTTP RESPONSE: 200 [application/json]
INFO | XDK DEVICE 1: {
INFO | XDK DEVICE 1:   "lux": "177.55"
INFO | XDK DEVICE 1: }

 

Manuel Cerny:

What is a perfect HTTP request answer that the XDK will need and not see a retcode other than zero ?

A perfect HTTP request answer can be found in the HTTP guide in Listing 2.
 

At the moment i have still a retcode 1309 - but i see the correct data.
How can i get rid of this - where can i see easy a failure text belonging to a retcode ?

I’m not quite sure which function you are referring to. You definitely get a reponse code 200 from the server which means your response is ok. It looks like you are sending different requests because of the different request responses.

The retcode 1309 is in hexadecimal equal to 0x051D which stands for RC_HTTP_INVALID_RESPONSE (Serval_Exceptions.h).

It could be the case that one of your servers does not unterstand the HTTP request of the XDK. I recommend to test the server interfaces of the sensor nodes with postman.

Kind regards,
Manuel

0 (0 Votes)
RE: HTTP request error code
Answer
11/17/16 8:58 AM as a reply to Manuel Cerny.

Hello Manuel, thanx for the fast feedback.
My first http get request in my application is yours out of the guide.
I have modified the function with the msg.ptr and return_code check.
I let it pass if i have a message - and print the return_code to see what happens.
Your demo request works fine - i got a ZERO return code - so all is correct.

On my own systems or http server if receive the request of the XDK, read and check the content of the message and then i answer with normal client.print sequences.
A correct Content.Lenght seems very importent to the XDK - otherwise no message content.

As you have seen - the XDK receives my data perfect - the system runs hour to hour without failure. The only point is the returncode 1309 detected from the XDK ?
Who generates this error code - my server did not send such a data entry ?
So something is different or wrong ?

The only point i have not implemented yet is Date and Last-Modified in my answer to the XDK ?

Date: Mon, 03 Oct 2016 21:16:16 GMT
Last-Modified: Thu, 01 Sep 2016 10:15:00 GMT


I will make some more tests this weekend with XDK http get calls to all of my systems like my smarthome gateway and the wiolink and wionode sensors - but here i will have another problem https is required ...

Yesterday i have made also first tests with XDK http post calls - i have seen xdk raw data on my servers - so that works too - next step read out all the message entries and provide to my other hard- and software. Also here my response to the XDK produces another retcode error 13.. - so this is my big nut to crack - wanna see ZERO here all the time...

 

0 (0 Votes)
RE: HTTP request error code
Answer
11/17/16 4:29 PM as a reply to Achim Kern.

Hello Achim,

I’m glad to help.
The content length is truly important because the content length is limited by the tcp packet size.
The error codes are generated by the serval stack onte the XDK if anything fails during the request. This means for example if your server does not send any response or if the XDK can’t read the response you will get an error.

We are aware HTTPS is still an issue on the XDK and are really sorry for that circumstance.

An HTTP post request is like an HTTP get request in general, but it is important to handle it on the server side and respond to post requests too.

As I said, the error code 1309 describes an invalid response. I would recommend to take a look at the interface Serval_Exceptions.h that describes all error codes.

Please let me know if you are making progress.

Kind regards,
Manuel

0 (0 Votes)
RE: HTTP request error code
Answer
11/18/16 6:47 PM as a reply to Manuel Cerny.
 INFO | XDK DEVICE 1: [x] Bosch XDK - initialization WiFi ...
 INFO | XDK DEVICE 1: [x] Bosch XDK - a WiFi IP was retrieved : 192.168.178.164 OK
 INFO | XDK DEVICE 1: [x] Bosch XDK - initialization HTTP REST Client ...
 INFO | XDK DEVICE 1: [x] Bosch XDK - HTTP REST Client running ...
 INFO | XDK DEVICE 1: [x] Bosch XDK - http request reading sequence = 1
 INFO | XDK DEVICE 1: [x] Bosch XDK - GET demo request from site http://23.22.14.18:80/ip ...
 INFO | XDK DEVICE 1: [x] Bosch XDK - retcode_status=0 (should be ZERO)
 INFO | XDK DEVICE 1: [x] Bosch XDK - now reading the response...
 INFO | XDK DEVICE 1: [x] Bosch XDK - len=33
 INFO | XDK DEVICE 1: [x] Bosch XDK - HTTP RESPONSE: 200 [application/json]
 INFO | XDK DEVICE 1: {
 INFO | XDK DEVICE 1:   "origin": "79.251.255.236"
 INFO | XDK DEVICE 1: }
 INFO | XDK DEVICE 1: **************************************************************************
 INFO | XDK DEVICE 1: [x] Bosch XDK - GET RedBearDuo5 BoschBME280 humidity sensor data ...
 INFO | XDK DEVICE 1: [x] Bosch XDK - retcode_status=0 (should be ZERO)
 INFO | XDK DEVICE 1: [x] Bosch XDK - now reading the response...
 INFO | XDK DEVICE 1: [x] Bosch XDK - len=18
 INFO | XDK DEVICE 1: [x] Bosch XDK - HTTP RESPONSE: 200 [application/json]
 INFO | XDK DEVICE 1: {"humidity": 49}
 INFO | XDK DEVICE 1: **************************************************************************
 INFO | XDK DEVICE 1: [x] Bosch XDK - POST XDK sensor data to RedBearDuo5 Http Server ...
 INFO | XDK DEVICE 1: [x] Bosch XDK - retcode_status=0 (should be ZERO)
 INFO | XDK DEVICE 1: [x] Bosch XDK - now reading the response...
 INFO | XDK DEVICE 1: [x] Bosch XDK - len=6
 INFO | XDK DEVICE 1: [x] Bosch XDK - HTTP RESPONSE: 201 [text/html]
 INFO | XDK DEVICE 1: okay
 INFO | XDK DEVICE 1: **************************************************************************

Edited by Manuel Cerny: Please refer to the community guidelines.
Comment: Please make sure to post only the related code pieces.

+1 (1 Vote)
RE: HTTP request error code
Answer
11/18/16 5:54 PM as a reply to Achim Kern.

Hello - all http post and get requests are working fine now.
The solution or failure was the correct content-length entry in the response.

As you see in my last post response - my server sends okay - normally 4 letters long - xdk wants 6 as correct entry - maybe he sees a linefeed and a carriage return ?

+1 (1 Vote)
RE: HTTP request error code
Answer
11/21/16 4:01 PM as a reply to Achim Kern.

Hello Achim,

great to hear that your requests are working fine.
The XDK is not limited to a content length of the response body (except the length of a TCP packet).
I just verified it on my HTTP server implementation:

INFO | XDK DEVICE 1: HTTP POST RESPONSE: 200 [text/plain]
INFO | XDK DEVICE 1: HTTP LENGTH: 16
INFO | XDK DEVICE 1: HTTP RESPONSE CONTENT: Post_request_ok


Unfortunately I cannot reproduce your issue. Please note that if you return a response from your server and declare it as HTML, I would recommend use an HTML format in your response. If you are returning plain text, you should declare the response as text/plain.

Kind regards,
Manuel

0 (0 Votes)