How to see the HTTP request that AngularJS is sending?

时间:2017-04-10 03:23:28

标签: javascript angularjs rest curl httprequest

I have a REST endpoint called myEndpoint that I can successfully hit using Curl like this:

curl \
--request DELETE \
--header "Content-Type: application/json" \
--header "Authorization: JWT eyJhbFciOiJ__FAKE__sInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InNhcWliIi__FAKE__9pZCI6NSwiZW1haWwiOiJzYXFpYi5hbGkuNzVAZ21haWwuY29tIiwiZXhwIjoxNDkxNzkyMzEzfQ.feGiXm__FAKE__ZS6V-OROM7EzekRzpu_5pwi865tz8" \
--data '{
    "myAttribute": "Something"
}' \
"http://localhost:3999/api/myEndpoint"

However, when my AngularJS code tries to call the same endpoint it fails saying that the mandatory myAttribute parameter was not provided. This is how angularJS is making the call:

  var httpParams = {'myAttribute': 'Something'};
  $scope.myPromise = $http.delete('http://localhost:3999/api/myEndpoint', httpParams).then(self.myEndpointSuccess, self.myEndpointFailure);

(AngularJS's attachment of the JWT token to the HTTP request is not shown, but I'm sure that is working)

How can I see exactly what HTTP request AngularJS is sending so that I can do an apples-to-apples comparison agains my working curl call?

Here is my Chrome's Developerenter image description here Tools -> Network tab. I don't see the information I'm seeking there:

3 个答案:

答案 0 :(得分:1)

$ http服务文档说$ http.delete有两个参数,URL和config。通过调用curl,我理解myAtribute是给你想要发送到端点的参数的名称,在这种情况下它应该在config对象的params属性或data属性中。

angular reference another question

答案 1 :(得分:0)

仅供参考,DELETE请求通常没有请求正文。

至于你的问题,RTFM; $http.delete的第二个arg应该是一个配置对象,所以在你的情况下

$http.delete('http://localhost:3999/api/myEndpoint', {data: httpParams})

答案 2 :(得分:0)

AngularJS为http请求提供$ http模块。您可以使用此模块发出特定请求,然后使用。处理请求。那么()哪个成功回调后跟一个错误回调