我正在创建登录和注册页面并且'面临问题,json结果取零值...我已经检查了全部代码但是我发现在这个htpclient中,httpparams正在对它们进行删除线请修复
private class AsyncDataClass extends AsyncTask<String, Void, String > {
@Override
protected String doInBackground(String... params) {
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
HttpConnectionParams.setSoTimeout(httpParameters, 5000);
HttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpPost httpPost = new HttpPost(params[0]);
String jsonResult = "";
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("name", params[1]));
nameValuePairs.add(new BasicNameValuePair("phoneno", params[2]));
nameValuePairs.add(new BasicNameValuePair("emailid", params[3]));
nameValuePairs.add(new BasicNameValuePair("password", params[4]));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
jsonResult = inputStreamToString(response.getEntity().getContent()).toString();
System.out.println("Returned Json object " + jsonResult.toString());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return jsonResult;
答案 0 :(得分:0)
这是否适用:HTTP Client removed from SDK 23
以下是解决此问题的构建脚本:
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
/* Apache HTTP Client has been removed from SDK Version 23 and up. Workaround See: https://developer.android.com/preview/behavior-changes.html#behavior-apache-http-client */
useLibrary 'org.apache.http.legacy'