相关疑难解决方法(0)

有什么可以替换http弃用的方法?

我正在按照教程进行操作,并且我已经批准了很多代码.

ArrayList<NameValuePair> dataToSend = new ArrayList<>();
dataToSend.add(new BasicNameValuePair("name", user.name));
dataToSend.add(new BasicNameValuePair("age", user.age));

HttpParams httpRequestParams = new BasicHttpParams();
HttpConnectionParamas.setConnectionTimeout(httpRequestParams, CONNECTION_TIMEOUT);
HttpConnectionParamas.setSoTimeout(httpRequestParams, CONNECTION_TIMEOUT);

HttpClient client = new DefaultHttpClient(httpRequestParams);
HttpPost post = new HttpPost(SERVER_ADDRESS + "Register.php");

try{
    post.setEntity(new UrlEncodedFormEntity(dataToSend));
    client.execute(post);
}catch (Exception e){
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

和另一个返回结果的POST方法

    HttpResponse httpResponse = client.execute(post);

    HttpEntity entity = httpResponse.getEntity();
    String result = EntityUtils.toString(entity);
    JSONObject jObject = new JSONObject(result);
Run Code Online (Sandbox Code Playgroud)

我发现,我可以代替NameValuePair

ContentValues values = new ContentValues();
values.put("name", user.name);
values.put("age", user.age + "");
Run Code Online (Sandbox Code Playgroud)

但我不知道其他人.

android androidhttpclient android-studio

6
推荐指数
2
解决办法
1万
查看次数