我正在向带有两个参数的 php 服务器发送 POST 消息,一个是 Base64 中的 HASH。Base64 使用字符“=”作为填充,因此它可以出现在哈希值中。
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "WAFFTE="));
nameValuePairs.add(new BasicNameValuePair("stringdata", "data"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
使用此代码,url 将通过 %3D 对“=”进行编码,但在这种情况下,服务器不会重新调整 id 值。我试过 selectinf 不同的编码,但没有区别。
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs),"UTF-8");
有什么帮助吗?