NetworkError: 400 Bad Request

1

When sending a post, I got the message in the NetworkError message: 400 Bad Request.

In the Development Environment no error occurs, data is synchronized from device to Tomcat on my internal network successfully.

I have published the system, in the device I configured the URL, and when trying to transmit the data I get the error NetworkError: 400 Bad Request

http://200.187.136.7:8080/nova/fw.rule?sys=TSE&usuario=teste&metodo=fw_addSessao&parametros=7b911e32-1432-45c3-8ee0-e316bad7a2f7|2|15/01/2017%2023:19:44|15/01/2017%2023:22:01|e8b5ed5c-d1bf-43c2-a7ad-cdb7699cc496|Outros|Teste%20|-7.99032|-34.8935

Parameters are:

sys=TSE

usuario=teste

metodo=fw_addSessao

parametros=7b911e32-1432-45c3-8ee0-e316bad7a2f7|2|15/01/2017%2023:19:44|15/01/2017%2023:22:01|e8b5ed5c-d1bf-43c2-a7ad-cdb7699cc496|Outros|Teste%20|-7.99032|-34.8935

everything is sent in text, the last parameter has concatenated various information like record id, latitude, longitude and I used the delimiter as the pipe "|" and from what I'm noticing the problem is it, the more in my internal network has no problem whatsoever with its use.

    
asked by anonymous 16.01.2017 / 16:30

1 answer

2

The 400 Bad Request error occurs when the server can not understand and process the corresponding request. Once you have checked that the server URL is actually correct, one possible solution is to code the parameters using the class URLEncoder , so it does not conflict with any reserved characters. Here's how it would look:

String parametroCodificado = URLEncoder.encode("?sys=TSE&usuario=teste&metodo=fw_addSessao&parametros=7b911e32-1432-45c3-8ee0-e316bad7a2f7|2|15/01/2017%2023:19:44|15/01/2017%2023:22:01|e8b5ed5c-d1bf-43c2-a7ad-cdb7699cc496|Outros|Teste%20|-7.99032|-34.8935", "utf-8");
String url = "http://200.187.136.7:8080/nova/fw.rule" + parametroCodificado ;

For more details on URLEncoder , see in the documentation .

    
16.01.2017 / 17:34