Angular $resource如何在URL中不发送参数

Angular $resource how to not send param in URL

本文关键字:参数 URL resource Angular      更新时间:2023-09-26
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, importTests是我的post请求与参数html。不幸的是,AngularJS在Request URL中包含了html参数,尽管这是一个post请求。我需要从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

this url to this one:http://localhost: 58861/api/ConfigTest/ImportHtml/1

使HTML参数只在正文中发送。

如果你不想将html作为参数发送,那么你不应该将其指定为参数…

testModel.html = '<html goes here>';
testModel.$importTests()