1

My question maybe unheard of or may even be impractical. But, I believe it is practical and acceptable.

Problem: PHP request and response in background thread.

Problem constraints:

  1. You know it uses POST method.
  2. It has two fields fname and lname as html ids that need to be filled.
  3. You get response in the same page i.e. index.php .

Pseudocode to solve the problem:

  1. Open the website in background. Something like openURL("xyz(dot)com");
  2. Read the data sent in html format.
  3. Change the value of the fields fname and lname to required fields "Allen" and "Walker."
  4. Now, submit the fields back to the server. ( Page has a submit button.)

Note: PHP code has a standard if-else check to check for those values. If the field is properly set, it then says "Success" else "Failed"

  1. Again, get the response sent by the server.
  2. Check if "Success" was returned.

  3. If "success" was returned, UPDATE UI thread for saying "JOB done". Else, "Job failed."

Note: I am not talking about using a WebView. Everything happens via a service or AsyncTask.


Now, this is a simple question, and any ideas or a direction is acceptable.

So, to recap. You have to open a webpage in background, change its field, submit it back and then get the response.


I know we can open a website and get its content. But, I would also like to know if what I said is possible or not. And, I know it is possible. And, that I only lack the knowledge on Java Web API, could you please guide me on this.

Thank You. And, Have a Good day!

Ariel
  • 2,471
  • 1
  • 26
  • 43

2 Answers2

1

use this link for best solution of calling web service without using WebView.

In this example fname and lname sent in namevaluepairs we get responce in json formet and parse json and get data also json parse defined in examples.

SAM
  • 122
  • 5
  • Sir, I am not talking about JSON or XML parsing. The webpage simply returns a php document with plain html. We have to edit the fields of the plain html document. And, then submit the fields and get the results back from the server. The result we got the second time is the desired result. The first result has a submit button on it. We just need to make sure we submit the page with fname and lname set. And, the html returned next is our main target file. – Ariel Apr 20 '16 at 11:32
0

What you are trying to achieve is to create a webservice call using a AsyncTask.

Like you have mentioned, you can make a post request within the AsyncTask, passing in the variables required for the request.

You can find a good example as shown: Sending HTTP Post Request with Android

Community
  • 1
  • 1
sihao
  • 431
  • 2
  • 11