mytechead

Android & Wordpress Help center

Send POST data to WebView urls

In order to send POST data in the url being loaded inside a WebView, instead of using the loadUrl(“http://myurl.com”) method postUrl() method can be used.

Documentation :

public void postUrl (String url, byte[] postData)
Since: API Level 5

Load the url with postData using “POST” method into the WebView. If url is not a network url, it will be loaded with {link loadUrl(String) instead.
Parameters
url The url of the resource to load.
postData The data will be passed to “POST” request.

Code snippet :

WebView mWebView = (WebView) findViewById(R.id.mWebView); // WHERE R.id.mWebView is of course webview in your layout file.

mWebView.postUrl("http://myurl.com",
EncodingUtils.getBytes("param1=value1&param2=value2","BASE64"));

Here first param to the postUrl() method is ‘url’ to which we want to send the data & the second parameter is the POST data. Since second param is of type bytes we have used ‘getBytes’ method of EncodingUtils class to get bytes from our POST data.

Advertisements

Single Post Navigation

4 thoughts on “Send POST data to WebView urls

  1. My spouse and I absolutely love your blog and find the majority of your post’s to be exactly what I’m looking for. Would you offer guest writers to write content available for you? I wouldn’t mind creating a post or elaborating on a number of the subjects you write about here. Again, awesome weblog!

    • thanks for the like… keep visiting for more tutorials… you can certainly mail [alchemist1063@gmail.com] me your content and i assure you to post it if its worthwhile 🙂

  2. Hi, Neat post. There’s a problem with your site in internet explorer, may test this� IE still is the market leader and a large element of folks will leave out your fantastic writing due to this problem.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: