Has anyone been successful at getting the HTTPPost() function to work over HTTPS on a CR6 datalogger connected to the Internet via Ethernet?
I have been working on a program to POST data to a web service endpoint we have written to receive observational data using the Open Geospatial Consortium SensorThings API specification. The API is working, and we are able to POST from several other types of devices. However, when trying to submit POST requests from a CR6 datalogger connected to the Internet via ethernet, I am continually getting "400 Bad Request" errors back from the server. So - the server doesn't like something in the POST requests I am sending.
Because I don't know exactly what the CRBasic HTTPPost() function does and I want to see the POST request that is being sent to see where it may be malformed, I have made attempts to send the POST request to a service at https://requestcatcher.com/. That service just catches the POST request and displays it in the browser. However, it uses HTTPS, whereas our SensorThings service is currently using HTTP.
CSI's documentation says that HTTPost() will do either HTTP or HTTPS, but no matter what I try over HTTPS, I get back an HTTP response of "Http comms Error". My program is scanning every 30s, and I get this response in the Public table after 8 seconds. Documentation says that the HTTPPost() function times out after 75 seconds, so I don't understand why I am getting this error at 8 seconds. According to the documentation, the function returns "the TCP socket that was created to communicate with the HTTP server". For that I'm getting back a value of 0, which is the result returned when the function fails.
I am able to do HTTPGet() over HTTP and HTTPS and get a valid response (commented example in my program below). So, my datalogger is connected to the Internet, has an IP address, can successfully get data over HTTP or HTTPS, can send POST requests over HTTP, but fails when trying to send POST requests over HTTPS.
Datalogger OS Version: 12.02 (I believe this the latest as I just updated)
To remove any complexity, I simplified my program to send a very simple HTTP POST request to https://jsh.requestcatcher.com (which you can navigate to and watch for requests to come in). This code gives me the above described error.
'CR6 Datalogger Public PTemp, Batt_volt Public http_header As String * 300 Public http_response As String * 1000 Public http_socket As Long Public content_string As String * 15 Public get_url As String * 50 = "https://api.ipify.org/?format=json" Public post_url As String * 50 = "https://jsh.requestcatcher.com/test" 'Define Data Tables. DataTable (Test,1,-1) 'Set table size to # of records, or -1 to autoallocate. DataInterval (0,15,Min,10) Minimum (1,batt_volt,FP2,False,False) Sample (1,PTemp,FP2) EndTable 'Main Program BeginProg Scan (30,Sec,0,0) PanelTemp (PTemp,15000) Battery (Batt_volt) http_header = "" content_string = "Hello world!" 'http_socket = HTTPGet(get_url, http_response, http_header) http_socket = HTTPPost(post_url,content_string,http_response,http_header) CallTable Test NextScan EndProg