Webservice issue in android
I am calling a json webservice using the code
HttpClient client = new DefaultHttpClient();
HttpGet method = new HttpGet(Url);
HttpResponse response = client.execute(method);
After exe开发者_如何学运维cuting the last line,app always catching the exception.
Could any one help me in this??
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());
}
}
Hi Can you let me know what exception you are getting. Also check whether the below permission is added.
<uses-permission android:name="android.permission.INTERNET" />
精彩评论