我是Android新手。请指导我。这是我的代码。如何使用OkHttp添加或更改代码?
try {
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//HttpClient httpclient = new DefaultHttpClient();
HttpClient httpclient =HttpClientBuilder.create().build();
try{
HttpPost httppost = new HttpPost("http://10.0.2.2/hari/test.php");
StringEntity se = new StringEntity("envelope",HTTP.UTF_8);
httppost.setEntity(se);
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 3000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
我在使用已弃用的代码时遇到了问题。如何在我的代码中使用OkHttp?我尝试在我的代码中包含OkHttp,但检测到更多错误。我正在使用Android API 20及更高版本。我也收到了utf_8的警告。
我该怎么办?