Andorid Webview How to POST data to application/x-www-form-urlencoded

时光毁灭记忆、已成空白 提交于 2021-01-27 14:32:58

问题


I have a Webview In that I am loading web with Query string perimeters like

String url = map.get("utype") + map.get("sid") + "/login/login.php?"+"&"+"strid" + "=" + map.get("strid")+"&"+"appmod" + "=" + map.get("appmod")+"&" +"ttype" + "=" + map.get("ttype")+"&" +"payp" + "=" + map.get("payp");

I am loading that Query string in webview

webView.loadUrl(url);

So Now Insted of using Query string I want to POST Parameters to x-www-form-urlencoded

These are my Parameters

strid = map.get("strid");
appmod = map.get("appmod");
ttype = map.get("ttype");
payp = map.get("payp");

I followed this but its not Working

can any one help me on this..

I want to POST data to x-www-form-urlencoded in Web-view

After posting I it will load my Web-server(website).

Update

I have Given these values for post

String postData="strid="+URLEncoder.encode(map.get("strid"), "UTF-8")+
"&appmod="+URLEncoder.encode(map.get("appmod"), "UTF-8")+
"&ttype="+URLEncoder.encode(map.get("ttype"), "UTF-8")+
"&payp="+URLEncoder.encode(map.get("payp"), "UTF-8");

Now after Adding The Details I have given this to at URL

webView.postUrl(url,postData.getBytes());

But still Its not working

can anyone suggest me whats wrong


回答1:


You need to call webView.postUrl(url, encodedData);

Values must be encoded with URLEncoder.encode(postData, "UTF-8") or "BASE64" depends on backend.

If its not working make sure you have url in correct format. You can also share it to here without exposing your values if you are not sure.



来源:https://stackoverflow.com/questions/53810759/andorid-webview-how-to-post-data-to-application-x-www-form-urlencoded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!