Url Encoding in AngularJS front end with Spring REST backend

时光总嘲笑我的痴心妄想 提交于 2019-12-13 06:14:37

问题


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 ?


回答1:


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'
    }
});

OR alternately:

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


来源:https://stackoverflow.com/questions/40963265/url-encoding-in-angularjs-front-end-with-spring-rest-backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!