How to intercept HTTP POST data from a web form

I have a web page (displayed in a browser, NOT a WebView ), and I would like to transfer some data (for example, using http POST) to a regular Android application.

I only need an application that needs to be launched and loaded with data. I know that an application can be launched by registering an intent filter, but I have lost some of the data transfer.

There is no need for the url to be real, the fake url is ok.

This can be done on BlackBerry using HTTP filters. Is there a way to do the same in Android?

Thanks in advance.

+4
source share
3 answers

Provide links on your web page, for example:

<a href="my.special.scheme://xyz.com/data1/data2"> 

In your onCreate() activity, you can access data through an intent object.

 Uri data = getIntent().getData(); String scheme = data.getScheme(); // "http" String host = data.getHost(); // "xyz.com" List<String> params = data.getPathSegments(); String first = params.get(0); // "data1" String second = params.get(1); // "data2" 
+4
source

The approach I should explore is to implement a very simple HTTP server service as part of your application. Encoding a small web server for your specific purpose would be extremely simple: listen on TCP port 80, accept the incoming connection, and then continue reading from the socket until \r\n\r\n sees the skip header and then read the POST data. Your web page is likely to access it through "localhost". I donโ€™t know if there are any serious obstacles using this method, but by performing a quick search I saw that there are already small web servers for Android, so this seems technically possible.

+2
source

Here are my two cents:

Although this is not really an interception, this approach does the job using the usual Intent Filter mechanism.

Example:

  • The browser opens a link to myownscheme: //myfakeurl.fake/http%3A%2F%2Factualurl.com
  • The Android app matches the intent filter and starts. It parses the parameter in the URL and decrypts it, getting "http://actualurl.com"
  • The android application makes a connection to the passed URL and retrieves the data.

      String encodedURL = getIntent().getData().getPathSegments().get(0); //Returns http%3A%2F%2Factualurl.com String targetURL = Html.fromHtml(encodedURL); //Returns http://actualurl.com //Now do the GET and fetch the data. 
+1
source

Source: https://habr.com/ru/post/1412534/


All Articles