【发布时间】:2015-08-25 09:04:09
【问题描述】:
function TestModel($resource, $location) {
var port = $location.port() == 80 || $location.port() == 443 ? "" : $location.port();
var root = $location.protocol() + '://' + $location.host() + ':' + port + '/api';
return $resource(root + '/ConfigTest/:action/:configurationId', { configurationId: '@configurationId', action: '@action' },
{
'importTests': {
method: 'POST',
params: { html: '@html' }
}
});
}
我在 AngularJS 中有这个 $resource,importTests 是我的带有参数 html 的 post 请求。不幸的是,AngularJS 在请求 URL 中包含了 html 参数,即使它是一个发布请求。我需要从 URL 中删除此参数,因为 URL 具有最大长度,这可能会导致错误。 所以基本上我需要的是修改上面的代码以从
http://localhost:58861/api/ConfigTest/ImportHtml/1?html=%3Ctable+border%3D%220%22+cellpadding%3D%220%22+cellspacing%3D%220%22+width%3D%22244%22%3E%0A%09%3Ctbody%3E%0A%09%09%3Ctr+height%3D%2220%22%3E%0A%09%09%09%3Ctd+height%3D%2220%22+width%3D%22112%22%3ETest1%3C%2Ftd%3E%0A%09%09%09%3Ctd+align%3D%22right%22+width%3D%22132%22%3E5000%3C%2Ftd%3E%0A%09%09%3C%2Ftr%3E%0A%09%09%3Ctr+height%3D%2220%22%3E%0A%09%09%09%3Ctd+height%3D%2220%22%3ETest+Leerzeichen%3C%2Ftd%3E%0A%09%09%09%3Ctd+align%3D%22right%22%3E6000%3C%2Ftd%3E%0A%09%09%3C%2Ftr%3E%0A%09%09%3Ctr+height%3D%2220%22%3E%0A%09%09%09%3Ctd+height%3D%2220%22%3ETest2%3C%2Ftd%3E%0A%09%09%09%3Ctd+align%3D%22right%22%3E7000%3C%2Ftd%3E%0A%09%09%3C%2Ftr%3E%0A%09%09%3Ctr+height%3D%2220%22%3E%0A%09%09%09%3Ctd+height%3D%2220%22%3ETest3%3C%2Ftd%3E%0A%09%09%09%3Ctd+align%3D%22right%22%3E8000%3C%2Ftd%3E%0A%09%09%3C%2Ftr%3E%0A%09%3C%2Ftbody%3E%0A%3C%2Ftable%3E%0A
这个网址到这个: http://localhost:58861/api/ConfigTest/ImportHtml/1
这样 html 参数只在正文中发送。
【问题讨论】:
标签: javascript angularjs http-post ngresource