我創建了一個類,這個類連接互聯網,然後發送一個請求到php script。我創建的就像 AsyncTask一樣,不在主線程中,為了能在4.0.4中執行。但是當我測試時,不能運行。程序可以在2.2上執行。問題出在哪裡呢?
class download extends AsyncTask {
protected String doInBackground(String s1, String s2) {
String result = "";
//http post
ArrayList nameValuePairs = new ArrayList();
nameValuePairs.add(new BasicNameValuePair("Vreme",s1));
nameValuePairs.add(new BasicNameValuePair("Datum",s2));
InputStream is=null;
try{
String adresa="http://senzori.open.telekom.rs/script.php";
HttpPost httppost = new HttpPost(adresa);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
return result;
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
return null;
}
}
doInBackground(String... params) 怎麼不是用的這個可變參數的方法,覆寫應該是覆寫這個方法啊
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
return null;
}