【问题标题】:Angular 8 - HTTP POST send password with special sign encoding problemAngular 8 - 带有特殊符号编码问题的 HTTP POST 发送密码
【发布时间】:2020-01-21 11:49:59
【问题描述】:

我的 POST 请求如下所示:

const loginParam = new HttpParams()
.set('Username', 'myUser')
.set('Password', ':(7vHa%+_(Tbc+m@');

this.http.post('/post', loginParam).subscribe(value => {
  console.log('success');
}, error => {
  console.log('error');
});

服务器回复(状态码 500)登录失败。会不会是密码发送不正确?以下是来自 devtools 的 sn-p:

查看表单数据(密码好像错了——加号消失了)

服务器是否有可能获得错误的密码? Postman 一切正常。

【问题讨论】:

  • 您有权访问服务器组件吗?因此,您可以尝试在发送密码之前使用encodeURI() 对您的密码进行编码,并在将密码交给真正的登录方法之前在服务器组件中对其进行解码。
  • @JohnArcher 不幸的是我无法访问服务器。
  • 好的。这对你有帮助吗? -> stackoverflow.com/a/22671551这里有一个类似问题的帖子(不幸的是没有答案):stackoverflow.com/questions/42023170/…
  • @JohnArcher 感谢您的提示。我找到了一个解决我问题的帖子。 stackoverflow.com/questions/53546691/…

标签: angular angular-cli


【解决方案1】:

我找到了一个帖子解决了我的问题:

Preserving + (Plus Sign) in URLEncoded Http Post request

现在,一切都像魅力一样。

【讨论】:

    猜你喜欢
    • 2018-02-13
    • 1970-01-01
    • 1970-01-01
    • 2011-02-21
    • 1970-01-01
    • 1970-01-01
    • 2014-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多