小编典典

在Angular的$ http中使用PUT方法时,向查询字符串添加参数

angularjs

我正在使用Angular的$http服务来发出Web api请求。当我使用GET方法时,两个参数值将添加到查询字符串中:

// http://foo.com/api/test?heroId=123&power=Death+ray
$http.get("/api/test", {
   params: { heroId: 123, power : "Death ray" }
})

但是,当我使用PUT方法时,参数被JSON编码并作为请求有效负载发送:

// {"params":{"heroId":123,"power":"Death ray"}}
$http.put("/api/test", {
   params: { heroId: 123, power : "Death ray" }
})

使用PUT时,如何强制将参数添加到查询字符串中?


阅读 506

收藏
2020-07-04

共1个答案

小编典典

$http.put$http.post或者$http.patch,该 配置 含有网址参数对象超出作为 第三个参数
,所述第二参数是所述请求体:

$http.put("/api/test",                                       // 1. url
          {},                                                // 2. request body
          { params: { heroId: 123, power : "Death ray" } }   // 3. config object
);

$http.put
参考文件

2020-07-04