Angular JS POST request not sending JSON data

前端 未结 7 1757
忘掉有多难
忘掉有多难 2020-12-01 10:30

I am trying to send an object as JSON to my webservice in Flask that is expecting JSON in the request data.

I have tested the service manually by sending JSON data a

7条回答
  •  星月不相逢
    2020-12-01 10:49

    I have tried your example and it works just fine:

    var app = 'AirFare';
    var d1 = new Date();
    var d2 = new Date();
    
    $http({
        url: '/api/test',
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        data: {application: app, from: d1, to: d2}
    });
    

    Output:

    Content-Length:91
    Content-Type:application/json
    Host:localhost:1234
    Origin:http://localhost:1234
    Referer:http://localhost:1234/index.html
    User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36
    X-Requested-With:XMLHttpRequest
    Request Payload
    {"application":"AirFare","from":"2013-10-10T11:47:50.681Z","to":"2013-10-10T11:47:50.681Z"}
    

    Are you using the latest version of AngularJS?

提交回复
热议问题