简体   繁体   English

为什么这些标头在Android WebView中不起作用?

[英]Why are these headers not working in Android WebView?

So I'm setting up a WebView to show a partners website. 因此,我正在设置一个WebView来显示合作伙伴的网站。 If the user does not have the feature set up. 如果用户没有设置功能。 it will redirect them to our website, since they are logged in on the device I need to pass our Authentication token in the request headers and our website will automatically log them. 它将重定向到我们的网站,因为它们已在设备上登录,因此我需要在请求标头中传递我们的身份验证令牌,然后我们的网站会自动对其进行登录。

It works on iOs but I can't get it to work on Android. 它可以在iO上运行,但无法在Android上运行。 I'm intercepting the redirect and if it is to our website I am adding the auth header. 我正在拦截重定向,如果重定向到我们的网站,则添加auth标头。 But it is not logging the user into the site. 但这不是将用户登录到站点。 It just shows our login page. 它仅显示我们的登录页面。 The code is bellow. 代码如下。

webView?.webViewClient = object : WebViewClient() {
    override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
        if(!url!!.contains("ourwebsite.com/authenticate"))
            return false
        val am: AccountManager = AccountManager.get(context)
        val token = am.getPassword(Application.getAccount())
        val extraHeaders: MutableMap<String, String> = mutableMapOf()
        extraHeaders.put(AUTH_KEY, token)

        view?.loadUrl(url, extraHeaders)
        return false

    }

So our server folks were kind enough to add some logs for me and I saw this in the recorded headers 所以我们的服务器人员很友好,可以为我添加一些日志,我在记录的标题中看到了

"auth-header": "some token",

When I'm adding the auth header in I'm adding with capitalization (because that is what is required by the server: 当我在其中添加auth标头时,我要使用大写字母添加(因为这是服务器的要求:

"Auth-Header"

Apparently the rom RFC 2616 - "Hypertext Transfer Protocol -- HTTP/1.1", Section 4.2, "Message Headers": states that headers are not case sensitive. 显然rom RFC 2616 - "Hypertext Transfer Protocol -- HTTP/1.1", Section 4.2, "Message Headers":指出标头不区分大小写。 :( :(

So our servers need to handle the all lowercase protocol. 因此,我们的服务器需要处理所有小写协议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM