如何在本机WebView中传递post参数?

Wel*_*ton 5 webview react-native

我有一个网址,我想在我的应用程序中打开,WebView以避免用户不得不从应用程序重定向到移动浏览器.但是,我想要显示的网页需要一些帖子参数,例如来自帖子表单.如果是GET情况,我只需将参数附加到网址即可.

<WebView
    source={{uri: 'https://mypage.com/index.php', headers: '---', body: '---'}}
    style={{marginTop: 20}}
  />
Run Code Online (Sandbox Code Playgroud)

我可以将它们放入headers或放入body,以什么格式放入?或者还有另一种方式吗?我想将参数设置为键值格式,即cat=himalayan&dog=pug&fish=shark

小智 11

你必须像这样在源代码中添加方法

<WebView
    source={{uri: 'https://mypage.com/index.php', headers: '---', body: '---',method:'POST'}}
    style={{marginTop: 20}}
  />
Run Code Online (Sandbox Code Playgroud)


小智 7

将这段代码放在正文中:

{ source: { uri: 'https://mypage.com/index.php', method: 'POST', body: 
'cat=himalayan&dog=pug&fish=shark' } 
Run Code Online (Sandbox Code Playgroud)