AngularJs $http.post() does not send data

前端 未结 30 2347
我在风中等你
我在风中等你 2020-11-22 02:51

Could anyone tell me why the following statement does not send the post data to the designated url? The url is called but on the server when I print $_POST - I get an empty

30条回答
  •  庸人自扰
    2020-11-22 03:22

    Angular

      var payload = $.param({ jobId: 2 });
    
                    this.$http({
                        method: 'POST',
                        url: 'web/api/ResourceAction/processfile',
                        data: payload,
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                    });
    

    WebAPI 2

    public class AcceptJobParams
            {
                public int jobId { get; set; }
            }
    
            public IHttpActionResult ProcessFile([FromBody]AcceptJobParams thing)
            {
                // do something with fileName parameter
    
                return Ok();
            }
    

提交回复
热议问题