Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android intent to POST URL?

Tags:

android

http

post

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?

like image 811
Alistair Avatar asked Oct 10 '22 13:10

Alistair


1 Answers

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);
like image 173
Estel Avatar answered Oct 14 '22 00:10

Estel