Reputation: 10125
I'm using Angular's $http
service to make web api requests. When I use the GET method, the two param values are added to the query string:
// http://foo.com/api/test?heroId=123&power=Death+ray
$http.get("/api/test", {
params: { heroId: 123, power : "Death ray" }
})
However, when I use the PUT method the params are JSON-encoded and sent as the request payload:
// {"params":{"heroId":123,"power":"Death ray"}}
$http.put("/api/test", {
params: { heroId: 123, power : "Death ray" }
})
How can I force the params to be added to the query string when using PUT?
Upvotes: 29
Views: 44779
Reputation: 7
If your api url is "api/test/heroId/power",
var data = 123+'/Death ray'
$http.put("api/test"+data);
Upvotes: -3
Reputation: 28289
With $http.put
, $http.post
or $http.patch
, the config object containing your url parameters goes as the third argument, the second argument being the request body:
$http.put("/api/test", // 1. url
{}, // 2. request body
{ params: { heroId: 123, power : "Death ray" } } // 3. config object
);
$http.put
documentation for reference
Upvotes: 57
Reputation: 4964
AngularJS send json data and not x-www-form-urlencoded format data. Though you can try the below one:
$http.put("/api/test", { heroId: 123, power : "Death ray" });
Upvotes: -3