将数据发送到 WebView 中加载的页面

编程入门 行业动态 更新时间:2024-10-24 09:17:03
本文介绍了将数据发送到 WebView 中加载的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有一个 WebView,我加载了 http://mysite/somepage.php

I have a WebView in my app and I load http://mysite/somepage.php

我知道我可以使用 GET 方法传递数据,因为那正好在 URL 字符串中.我想知道如何使用 POST 方法将数据传递到页面.我尝试搜索,但找不到任何具体内容.谢谢.

I know I can pass data using the GET method because that would just be right in the URL string. I was wondering how I could pass data to the page using the POST method. I tried searching but I cannot find anything specific. Thanks.

推荐答案

WebView 中有一个名为 postUrl 的方法.

There's a method called postUrl in WebView.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WebView webView = new WebView(this);
    setContentView(webView);

    String url = "http://mysite/somepage.php";
    String postData = "postvar=value";

    webView.postUrl(url, EncodingUtils.getBytes(postData, "base64"));
}

如果 base64 不起作用,请尝试使用 BASE64.

If base64 didn't work, try BASE64 alternatively.

希望一切顺利.

这篇关于将数据发送到 WebView 中加载的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-30 11:49:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/777209.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   加载   页面   数据   WebView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!