Networkerror: 400 Bad Request

Asked

Viewed 1,752 times

1

When sending a post I received by retrofit in the log the message Networkerror: 400 Bad Request.

In Development Environment no error occurs, data is synchronized from device to Server ( Tomcat ) from my internal network successfully.

I published the system, on the device I configured the URL, and while trying to transmit the data I get 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

The 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 Id of the record, latitude, longitude and I used as bounder the pipe "|" and for what I am noticing the problem is it, but in my internal network has no problem with its use.

  • You say that in Amabiente development does not occur errors, that means that when available for production this error happens? You checked if the URL is correct?

  • Yes the url is correct, and once I got it from the AE log, I did the following where the "|" was changed to ";" then the error became the 500 that indicates an error in the Server or POST arrived on the server and as my rule of business waits for a delimiter and arrived another the routine broke.

  • Try using the URL ENCODE. This problem you are giving is a request. You are not making the request correctly on the server.

  • See: http://www.url-encode-decode.com/

  • Hello Ack Lay good afternoon, understood well would be to pick up the text where I have several concatenated information and make a meeting on it? and on the server a Decode?

  • Exactly. Try this, maybe there are some characters that are conflicting with default characters of the URL and is giving problem in the interpretation.

Show 1 more comment

1 answer

2


The mistake 400 Bad Request occurs when server cannot understand and process the corresponding request. Once you have checked if the server URL is actually correct, a possible solution is to encode the parameters using the class Urlencoder, so that it doesn’t conflict with some reserved character. See 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.

  • 1

    My dear Ack Lay, you were absolutely right, thank you very much man, thanks even, saved the day

Browser other questions tagged

You are not signed in. Login or sign up in order to post.