使用Spring REST后端在AngularJS前端编写Url代码

时间:2016-12-04 20:26:43

标签: angularjs spring rest url url-encoding

快速提问。我有一个与Spring REST后端通信的AngularJS前端。 URL编码仅用于编码在url中传递的参数(对于application / x-www-form-urlencoded)。我不必担心身体的编码,对吗?

1 个答案:

答案 0 :(得分:1)

对于application/x-www-form-urlencoded的内容类型,帖子消息的正文需要进行uri编码:

$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);

有关详细信息,请参阅: