我有一个登录屏幕,当用户单击登录按钮时,我需要向 URL 地址添加一些信息。这是我过去数据的代码:
private String postData() {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(PropertyManager.getLoginURL());
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("u", Uri.encode(PropertyManager.getUserId())));
nameValuePairs.add(new BasicNameValuePair("p", Encryption.encrypt(PropertyManager.getPassword())));
nameValuePairs.add(new BasicNameValuePair("v", PropertyManager.VER));
nameValuePairs.add(new BasicNameValuePair("t", "0"));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httppost);
String responseBody = EntityUtils.toString(response.getEntity());
Log.i("Server Response 1: ", responseBody);
if (response.containsHeader("Set-Cookie")) {
PropertyManager.setSessionID(extractSessionId(response.getHeaders("Set-Cookie")[0].getValue()));
}
return responseBody;
} catch(UnsupportedEncodingException usee) {
usee.printStackTrace();
} catch(ClientProtocolException cpe) {
cpe.printStackTrace();
} catch(IOException ioe) {
ioe.printStackTrace();
}
return null;
}
实际上,当我的设备通过 WiFi 和 3G 连接到 Internet 时,这种方法可以正常工作。但仅对于一台设备(索尼爱立信 - Xperia),当它连接到 3G(WiFi 可以)时,服务器会发送无意义的响应。
我需要查看我的连接地址及其详细参数。我写了这段代码:
Log.i("Requestd Connection", httppost.getURI().toString());
但是,我只能看到我的 URL,没有任何 nameValuePairs 参数。任何建议将不胜感激。