Jquery .ajax fails when basic auth username has @ symbol (ios / cordova)

后端 未结 3 540
無奈伤痛
無奈伤痛 2021-01-02 16:32

I have a phonegap app w/ jQuery 1.9.1 Worked great as long as the username doesn\'t have \'@\' symbol in it (like in email addresses). It only fails on iOS.

I suspec

3条回答
  •  日久生厌
    2021-01-02 17:13

    Try wrapping encodeURIComponent() before base64 encoding.

    beforeSend: function (xhr) {
            xhr.setRequestHeader("Authorization",
                "Basic " + $.base64.encode(encodeURIComponent(this.username + ":" + this.password)));
        },
    

提交回复
热议问题