如何从webView.postURL()获取json响应。如何在webview中直接发布数据时获得json响应。
public class MainActivity extends Activity {
private WebView webView;
String postData = "name=xyz&pass=xyz123";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.webView = new WebView(this);
setContentView(this.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
return false;
}
});
webView.postUrl("http://10.0.2.2/login.php",EncodingUtils.getBytes(postData,"BASE64"));
}
serversidecode -
<?php
print json_encode(
array(
'name' =>$_POST['name'],
'pass'=>$_POST['pass']
)
?>