我使用代码
调用json webserviceHttpClient client = new DefaultHttpClient();
HttpGet method = new HttpGet(Url);
HttpResponse response = client.execute(method);
执行最后一行后,应用程序始终捕获异常。
任何人都可以帮助我吗?
答案 0 :(得分:1)
try this
HttpPost httppost;
HttpClient httpclient;
List<NameValuePair> nameValuePairs;
String userInfo[] = getUserInfo();
String uname = userInfo[0];
String pass = userInfo[1];
if(uname != null && pass != null) {
String bytesSent;
httppost = new HttpPost(getURL());
httpclient = new DefaultHttpClient();
nameValuePairs = new ArrayList<NameValuePair>(2);
String reminderstatus = "P";
nameValuePairs.add(new BasicNameValuePair("doAction", "something"));
nameValuePairs.add(new BasicNameValuePair("username",uname ));
nameValuePairs.add(new BasicNameValuePair("password", pass));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
InputStream is = response.getEntity().getContent();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(20);
int current = 0;
while((current = bis.read()) != -1) {
baf.append((byte)current);
}
bytesSent = new String(baf.toByteArray());
}
}
答案 1 :(得分:0)
<uses-permission android:name="android.permission.INTERNET" />