Very Simple AngularJS $http POST Results in '400 (Bad Request)' and 'Invalid HTTP status code 400'

前端 未结 3 1595
有刺的猬
有刺的猬 2020-12-09 12:34

I have a very simple .NET Web API hosted in Azure, with two very simple methods:

[EnableCors(origins: \"http://simpleapiearl.azurewebsites.net\", headers: \"         


        
3条回答
  •  不思量自难忘°
    2020-12-09 12:49

    With AngularJS you can do in an easier way.

    You can inject $httpParamSerializer and then prepare your data through $httpParamSerializer(data).

    So your call should look something like:

    $http({
        method: 'POST',
        url: 'http://simpleApiEarl.azurewebsites.net/api/envelopes',
        data: $httpParamSerializer(env),
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
      })
    

提交回复
热议问题