2014-07-15 38 views
0

所以,當我就與無法發送POST請求,因特殊字符的密碼

httpClient.execute(httpPost) 

POST請求我得到以下輸出:

09:09:12.181 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "username=qliu&password=213%40vPi" # <==== THIS LINE 
    09:09:12.283 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 200 OK[\r][\n]" 

我的密碼實際上是[email protected]而不是213%40vPi但我不知道如何逃避「@」符號?

String password = "[email protected]"; // TODO: how to escape @ 

回答

0

改用StringEntity類代替。

HttpPost prepareLoginHttpPost() { 
     HttpPost httpPost = new HttpPost(Configurations.SAND_LOGIN_URL); 

     StringEntity authorizationInJSON_Entity = new StringEntity(Configurations.authorizationInJSON); 

     httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded"); 
     httpPost.setEntity(authorizationInJSON_Entity); 

     return httpPost; 
    }