Alistair
Alistair

Reputation: 71

Android intent to POST URL?

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?

Upvotes: 5

Views: 5729

Answers (2)

Alistair
Alistair

Reputation: 71

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.

Upvotes: 0

Estel
Estel

Reputation: 2204

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);

Upvotes: 4

Related Questions