For this site
What i am trying to simulate is clicking the button "7" using HttpClient POST and then retrieving the value of the Input screen of the calculator using JSoup and setting it in an edit text box on the android app. The code is running fine with no errors, but i am getting a blank entry.
I utilized HttpClient of Apache library. Here is the code
// Title AsyncTask
private class Title extends AsyncTask<Void, Void, Void> {
String title, response1;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
try {
makePostRequest();
//postData("");
// Connect to the web site
Document document = Jsoup.connect(url).get();
// Get the html document title
title = document.title();
Elements E1 = document.select("input[name=Input]");
Element E2 = E1.first();
title = E2.val();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Set title into TextView
EditText txttitle = (EditText) findViewById(R.id.editText);
txttitle.setText(title);
mProgressDialog.dismiss();
}
private void makePostRequest() {
HttpClient httpClient = new DefaultHttpClient();
// replace with your url
HttpPost httpPost = new HttpPost(url);
//Post Data
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(1);
nameValuePair.add(new BasicNameValuePair("seven",""));
//Encoding POST data
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
// log exception
e.printStackTrace();
}
//making POST request.
try {
HttpResponse response = httpClient.execute(httpPost);
// write response to log
Log.d("Http Post Response:", response.toString());
} catch (ClientProtocolException e) {
// Log exception
e.printStackTrace();
} catch (IOException e) {
// Log exception
e.printStackTrace();
}
}
}
Does anyone have any idea what i am doing wrong here? The website is not mine and therefore i cannot add JavaScript. Am new to Android and Java Programming.
Please let me know if i can provide any other information i may have missed here.
Thank you.