带有Spring REST后端的AngularJS前端中的网址编码 [英] Url Encoding in AngularJS front end with Spring REST backend

查看:111
本文介绍了带有Spring REST后端的AngularJS前端中的网址编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速提问.我有一个与Spring REST后端通信的AngularJS前端.仅对URL中传递的参数进行编码时才需要URL编码(对于application/x-www-form-urlencoded).我不必担心体内的编码,对吗?

quick question. I have an AngularJS front end communicating with a Spring REST backend . URL encoding is only necessary for encoding parameters passed in the url (for application/x-www-form-urlencoded). I don't have to worry about the encoding in the body, correct ?

推荐答案

对于application/x-www-form-urlencoded的内容类型,帖子消息的主体需要使用uri编码:

For content type of application/x-www-form-urlencoded the body of a post message needs to be uri encoded:

$http({
    url: myUrl,
    method: 'POST',
    data: $httpParamSerializerJQLike(myData),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
});

或交替:

var config = {
    transformRequest: $httpParamSerializer,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
};

$http.post(myUrl, myData, config);

有关更多信息,请参见:

For more information, see:

  • AngularJS $httpParamSerializer Service API Reference
  • AngularJS $httpParamSerializerJQLike Service API Reference

这篇关于带有Spring REST后端的AngularJS前端中的网址编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆