[英]HttpPost works on Android's SDK 8, but not SDK 17
When I insert SDK 17 into the manifest file, nothing works (it does not load). 当我将SDK 17插入清单文件时,没有任何效果(无法加载)。 But when I insert SDK 8, it works.
但是,当我插入SDK 8时,它可以工作。
private void loadq(){
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://iwindroids.ru/app/fla/getq");
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null){sb.append(line + "\n");}
result = sb.toString();
JSONObject jObject = new JSONObject(result);
String t = jObject.getString("t").replace("--", "—");
String a = jObject.getString("a");
//String i = jObject.getString("i");
TextView et = (TextView) findViewById(R.id.textView1);
EditText at = (EditText) findViewById(R.id.editText2);
et.setText(t+".");
at.setText(a);
live();
showTimer();
} catch (Exception e){}
finally {try{if(inputStream != null)inputStream.close();}catch(Exception squish){}}
}
Thank You! 谢谢!
You have a NetworkOnMainThreadException
. 您有一个
NetworkOnMainThreadException
。 Look in the LogCat to see it. 在LogCat中查看以查看它。 You have to place your code in an AsyncTask or thread.
您必须将代码放在AsyncTask或线程中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.