0

I tryed to write an app that posts a form to a website and then gets the result which will later be used in Jsoup, but everytime the app is run I get the same website back as a result. The website:Link

I used this for an example:Link

I saw somewhere on this site that you have to put an action with the url but this doesn't work either.

Part of my app:

protected String doInBackground(String... params) {

        String url = "http://www.ap-ljubljana.si/vozni_red2/VR1.php";
        HttpPost post = new HttpPost(url);
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();

        parameters.add(new BasicNameValuePair("VSTOP_IME", vhod));
        parameters.add(new BasicNameValuePair("IZSTOP_IME", izhod));

        try {
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters);
            HttpClient client = new DefaultHttpClient();
            post.setEntity(entity);
            HttpResponse response = client.execute(post);
            html_response = EntityUtils.toString(response.getEntity());

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


        return null;
    }


}
Community
  • 1
  • 1
Snipex
  • 9
  • 8

1 Answers1

0

Change your url from

  String url = "http://www.ap-ljubljana.si/vozni_red2/VR1.php/";

to

  String url = "http://www.ap-ljubljana.si/vozni_red2/VR2.php";

Remove String action;

Thats all.

The action parameter is there to tell the 'form' to which url to post the data to. If the action parameter is empty or missing then the form will post to the same url as it's page.

greenapps
  • 11,154
  • 2
  • 16
  • 19
  • Why exactly does this work? I mean the form is on the VR1.php page. If I open VR2.php page on browser I get a tottaly different page. – Snipex Jul 02 '14 at 20:16
  • If you open VR2.php in a normal browser than the method is not POST. It is more a get without parameters. The php script can deliver you anything it wants. Indeed the
    is on VR1.php. But your app does not have to call that script as your app (well you) already knows that there is a
    with such and such input fields. If you open VR1.php in a normal browser, fill it in and click the button then the browser will post to script VR2.php. That's why your app has to do that too. The script will 'see' that there is a post. Read the name-value pairs and upon that decide which html to make..
    – greenapps Jul 02 '14 at 20:23