【问题标题】:Response header not decoded correctly in AngularJS [duplicate]AngularJS中的响应标头未正确解码[重复]
【发布时间】:2017-01-20 09:03:33
【问题描述】:

我正在使用 $http() AngularJS 函数向 webapi 发出 GET 请求

这是我的 GET 请求:

http://blahblahblah/api/.....&chartTitle=Instrument:%20%C3%A0%C3%9F%C3%A9%C3%A7%C3%B8%C3%B6

在实际响应中看到的响应标头:

chartTitle: Instrument: %C3%A0%C3%9F%C3%A9%C3%A7%C3%B8%C3%B6

当我使用 headers("charttitle") 检索标题时,我收到的值为:

Instrument: à Ãéçøö

而不是预期的:

Instrument: %C3%A0%C3%9F%C3%A9%C3%A7%C3%B8%C3%B6 

我尝试为 HTML 页面设置 UTF-8 编码,但我仍然得到这样的字符串

【问题讨论】:

  • 尝试添加这个,$http.get("http://youraddress", {headers : {'Content-Type' : 'application/json; charset=UTF-8'})
  • 我试过但很遗憾没有成功
  • 请在您解码标头的位置添加代码。
  • @Sravan 请到这里查看更详细的问题 -> stackoverflow.com/questions/41718364/… 谢谢!
  • 请检查相同的问题,我发布了答案。

标签: javascript angularjs string http


【解决方案1】:
i think you using $http like below

$http.get('/someUrl').
  success(function(data, status, headers, config) {
     // Here you can access your all headers params
  })
  .error(function(data, status, headers, config) {
     // Here you can access your all headers params
  });

【讨论】:

  • 您能详细说明一下吗?我没有得到你的解决方案,谢谢
猜你喜欢
  • 2020-10-20
  • 2015-02-28
  • 2016-06-21
  • 1970-01-01
  • 2017-10-27
  • 2019-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多