0

I have this code

httpUriRequest = new HttpPost(address.toString());
((HttpPost)httpUriRequest).setEntity(new ByteArrayEntity(restParams.postData()));
httpUriRequest.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");

When I'm sending "asd+asd" server gets "asdasd" or "asd asd". Also I try to send this string by rest-client to server and it works well.

So what's the problem? Can anyone suggest some solution?

Hayk Nahapetyan
  • 4,452
  • 8
  • 42
  • 61

1 Answers1

0

Its replacing "+" with space because in the HTML URL Encoding the "+" symbol is considered as the space and its always replaced with the space.

Basically you need to make sure the variables you are passing are encoded (the '%' character is a special character in URL encoding).

Any special characters - %,?,&, etc... need to be encoded. They are encoded with '%' and their hex number. So '%' should become '%25', '&' becomes '%26', etc.

Check out: escape, or encodeURI / encodeURIComponent for why you should avoid using escape.

One solution is that you make your request url into the Post method and post your request in the form of NameValuePair.

Check out the URL Encoding Reference

Community
  • 1
  • 1
GrIsHu
  • 29,068
  • 10
  • 64
  • 102