因此,当我使用邮递员(谷歌应用程序)将帖子方法发送到我的网络服务器上的我的php文件时,我得到了一个完整的回复所有正确的信息。但是当我试图在android上做同样的事情时,我每次都会得到[]。
@Override
protected Profile doInBackground(Void... params) {
ArrayList<NameValuePair> dataToSend = new ArrayList<>();
dataToSend.add(new BasicNameValuePair("name", user.name));
dataToSend.add(new BasicNameValuePair("password", user.password));
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpParams, CONNECTION_TIMEOUT);
HttpClient client = new DefaultHttpClient(httpParams);
HttpPost post = new HttpPost("http://www.secretvoice1.com/getData.php");
Profile returnUser = null;
try {
HttpResponse httpResponse = client.execute(post);
post.setEntity(new UrlEncodedFormEntity(dataToSend));
client.execute(post);
HttpEntity entity = httpResponse.getEntity();
Log.d("11111:", httpResponse.toString());
String result = EntityUtils.toString(entity);
System.out.println(result);
Log.d("222222", result);
JSONObject jsonObject = new JSONObject(result);
if (jsonObject.length() == 0) {
returnUser = null;
Log.d("this:", "here");
} else {
//String name = jsonObject.getJSONArray("name");
//String password = jsonObject.getString("password");
//String email = jsonObject.getString("email");
returnUser = new Profile(user.name, user.password, user.email);
}
catch(Exception e){
e.printStackTrace();
}
return null;
}
}