Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to intercept http POST data from web form

I've a web page (being displayed in a browser, NOT a WebView), and I'd like to pass some data (using http POST for instance) to a regular android app.

I only need the app to be launched and fed with data. I know the app can be launched by registering an intent filter, but I'm lost on the data passing part.

There's no need for the URL to be real, a fake URL is fine.

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

Thanks in advance.

like image 363
Mister Smith Avatar asked May 15 '12 09:05

Mister Smith


People also ask

How do you intercept HTTP data?

Manually intercepting HTTP clients To manually intercept traffic from a client that doesn't have automatic setup, you need to do two things: Configure the HTTP proxy settings to point to HTTP Toolkit. Ensure the client trusts your HTTPS certificate (if you're using HTTPS)

Can you intercept an HTTP request?

To intercept HTTP requests, use the webRequest API. This API enables you to add listeners for various stages of making an HTTP request. In the listeners, you can: Get access to request headers and bodies and response headers.

What is HTTP intercepting?

HTTP traffic passing through the proxy server can be intercepted. An intercepted request or response means the roundtrip is halted by the server, awaiting manual action. Stalled requests/responses can be inspected and (optionally) edited, before letting them continue to be sent/received.

What is HTTP interceptor in Javascript?

Interceptors are code blocks that you can use to preprocess or post-process HTTP calls, helping with global error handling, authentication, logging, and more.


2 Answers

In your web page put links like:

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

In your activity's onCreate() you can access the data through the 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"
like image 147
Ronnie Avatar answered Nov 14 '22 23:11

Ronnie


The approach I would investigate into is to implement a very simple HTTP server service as part of your application. Coding a small web server for your exact purpose would be extremely simple: Listen on TCP port 80, accept incoming connection, then keep reading from socket until \r\n\r\n is seen to skip the header, and then read the POST data. Your web page would presumably access it via 'localhost'. Whether there are any major hurdles with this method I don't know, but on doing a quick search I've seen there are already small Android web servers available, so technically it seems possible.

like image 42
Trevor Avatar answered Nov 14 '22 23:11

Trevor