5

I have the following code (simplified for simplicity) which takes the user to the URL specified:

    Button b = (Button) findViewById( R.id.button );
    b.setOnClickListener( new OnClickListener() {
        public void onClick( View v ) {
                Intent i = new Intent( Intent.ACTION_VIEW );
                i.setData( Uri.parse( "http://example.com/myform/?a=b&c=d&e=f" ) );
                if (i.resolveActivity(getPackageManager()) != null) {                    
                            startActivity( i );
                }
        }
    } );

which works well, but is a little ugly because the CGI parameters are shown in the URL bar of the Android web browser (they're various ugly session keys, etc). Is there a way to do the same using HTTP POST so they're hidden?

Flimm
  • 136,138
  • 45
  • 251
  • 267
Alistair
  • 71
  • 1
  • 3
  • 1
    I doubt it, since most apps that can receive such an intent won't be able to do a post. – Stefan H Singer Jul 11 '11 at 08:55
  • "Yes We Can!"... but with a trick. Check out this answer: http://stackoverflow.com/questions/4080517/launch-default-browser-with-intent-and-post-parameters#9909613 – Pascal Dec 11 '13 at 08:28

2 Answers2

4

It's not possible in the browser, but it would be possible if you used a WebView:

byte[] post = EncodingUtils.getBytes("a=b&c=d&e=f", "BASE64");
webview.postUrl("http://example.com/myform/", post);
Estel
  • 2,154
  • 2
  • 18
  • 25
0

In the end, I continued to use HTTP GET, but set a cookie then redirected the browser to a 'clean' URL without the session parameters.

Alistair
  • 71
  • 1
  • 3