EHS5-E problem with HTTP POST request | Telit Cinterion IoT Developer Community
January 18, 2018 - 8:58am, 1379 views
Hi all. I faced with the following problem during sending HTTP POST request.
I got the message from server "302 The document has moved" during POST. I use python and php om remote side. Both script did this message and both scripts works properly with requests from other devices (curl, web-form).
I use native Java code without any AT-command. The code with Java is more reliable and controlled.
My code:
String url = "http://myserver.ru/o/uploader.php?mode=gupload&contr=dix999";
HttpConnection conn = (HttpConnection) Connector.open(url);
conn.setRequestMethod(HttpConnection.POST);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
OutputStream os = conn.openOutputStream();
int code = conn.getResponseCode();
Here I got 302 message in "code" variable.
Googling I found such errors with possible redirections on remote web server. But I don't have redirection to HTTPS on my server. For such messages I must enable to foloow redirect but JavaME doesn't have this option.
But JavaSE has class HTTPUrlConnection instead of HTTPConnection. It has the method
conn.setInstanceFollowRedirects(true);
What should I do for EHS-5? Has anybody the experience to send POST HTTP request with Java?
Thank you
Hello,
It seems that there is a redirection and the API does not follow redirections automatically.
You can read the server reply and get the new link or just call getHeaderField("Location") on the connection and then open a new connection with this link.
Best regards,
Bartłomiej