【问题标题】:Angular $resource how to not send param in URLAngular $resource 如何不在 URL 中发送参数
【发布时间】: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


    【解决方案1】:

    如果您不想将 html 作为参数发送,则不应将其指定为参数...

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

    【讨论】:

    • 如果我像这样从服务中调用它? TestModel.html = html; TestModel.importTests({ configurationId: configurationId, action: 'ImportHtml' }) 和这样的模型? 'importTests': { method: 'POST' } ... 像这样,参数也不在体内
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-07
    • 2017-01-14
    • 1970-01-01
    • 2018-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多