http client yavaş
20.06.2016 - 07:44
merhabalar kodlarım aşşağıda
ağdaki bir web servera httpget isteği yaptıgım zaman yaklaşık olarak 2 sn bekletıyor. normal tarayıcıdan aynı istedği yaptığımda bir sıkıntı yok
Problem nedir acaba ?
package com.example.sabri.test;
import android.content.SharedPreferences;
import android.net.http.AndroidHttpClient;
import android.os.AsyncTask;
import android.os.StrictMode;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity {
Button button1;
Button button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.button);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.4.1/1");
try {
httpclient.execute(httppost);
} catch (IOException e) {
}
}
});
button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpgetx = new HttpGet("http://192.168.4.1/0");
try {
httpclient.execute(httpgetx);
} catch (IOException e) {
}
}
});
}
}
38
Görüntülenme
0 Beğeni