0

I am new in android.I am suffered from last two days.I have researched lot but i didn't get post file redirect to url.I have implimented post data rediect on url.But I am not getting that how to directly send file on url. I have implimented this

 //This is the section of code that fixes redirects to external apps
 String postData="writeanystringhere";
    webView.setWebViewClient( new WebViewClient(){
        @Override public boolean shouldOverrideUrlLoading(WebView view, String url){
            return false; } });

mWebView1.postUrl("http://weburl.com/?module=server&do=test", EncodingUtils.getBytes(postData, "BASE64"));

so i need help how to send file like this on url.**Can i post file through this?**which method will be used at the place of EncodingUtils.getBytes().

Narendra.kr
  • 181
  • 3
  • 12

3 Answers3

0

Instead of sending your data through with Web View, I think you should do a little bit hack for it.
Create a web view client for catching the url.

private class MyWebviewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.e(TAG,url);
            if(url.startsWith("http://weburl.com/?module=server&do=test")){
               //SEND YOUR FILE HERE 
               return true;
            }
            if(url.startsWith("RESPONSE_URL"){
            //HANDLE THE RESPONSE AND SEND IT WEB VIEW
                return true;
            }
    }

You can send your file into the comment block with using retrofit or volley or whatever you like. After the sending the file, you should override the response to continue to use webview.
Do not forget to use webView.setWebViewClient(new MyWebviewClient());

Abdullah Tellioglu
  • 1,434
  • 1
  • 10
  • 26
0

See the documentation.

You can only use WebView's postUrl with application/x-www-form-urlencoded bytes. While it's still "possible" to post files with urlencoded than multipart, it's not appropriate, and really bad. You need to utilize WebViewClient or WebChromeClient to handle this just like @AbdullahTellioglu mentioned.

viz
  • 1,247
  • 16
  • 27
-1

Use retrofit library...Its the best and the fastest when doing restfull tasks..Check it out here

Siva agarwal
  • 97
  • 1
  • 8