Add parameters to query string when using PUT method with Angular's $http

后端 未结 3 882
一向
一向 2021-01-01 11:08

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:

//         


        
相关标签:
3条回答
  • 2021-01-01 11:15

    If your api url is "api/test/heroId/power",

    var data = 123+'/Death ray'

    $http.put("api/test"+data);

    0 讨论(0)
  • 2021-01-01 11:36

    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" });
    
    0 讨论(0)
  • 2021-01-01 11:42

    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

    0 讨论(0)
提交回复
热议问题