I am trying to post my form data from android to website. I have searched around and here is the code that i usually find.
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://localhost/adminp/script.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "Hi"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
however two things that are creating problem. Firstly, UrlEncodedFormEntity and execute both show errors:
"Error:(94, 29) error: unreported exception UnsupportedEncodingException; must be caught or declared to be thrown"
and
"Error:(97, 52) error: unreported exception IOException; must be caught or declared to be thrown".
please guide me how to solve this issue.
second, HTTPClient etc have been deprecated since API 22, if someone knows about latest tutorial for method to post (URLConnection), please share with me, I'd be highly in debt.