I am new in android and i want to connect my app with mysql using php but it doesnt work, is some thing wrong in my code? please help me:
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2:8888/jobs/mobile/home/searchJobs");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
//add data for post
nameValuePairs.add(new BasicNameValuePair("keywords","keyword for search" ));
nameValuePairs.add(new BasicNameValuePair("location", "Location value"));
//set url encoded entity
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
String responseStr = EntityUtils.toString(resEntity).trim();
Toast.makeText(Search_result.this, "response: "+responseStr, 1000).show();
// you can add an if statement here and do other actions based on the response
Log.v("tag", "Response: " + responseStr);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
And this the errors:
Based on your log check the following:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.