Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`$http:badreq Bad Request Configuration` - from angular post method, what is wrong here?

I am developing sample app to learn the angularjs using node.js. when i post the data to backend to create a new family i am getting error as :

Error: $http:badreq
Bad Request Configuration
Http request configuration url must be a string.  Received: 
{
    "method":"POST",
    "url":"api/family",
    "data":  {
                "username":"fagruddin",
                "password":"valaanur",
                "familyLeader":"fagruddin",
                "husband":"fagruddin",
                "wife":"rejiya",
                "child":2
     },
     "headers":{
         "Content-Type":"application/x-www-form-urlencoded"
     }
}

what is wrong here? any one help me to solve this?

Live Demo for your reference

like image 745
user2024080 Avatar asked Jul 27 '26 15:07

user2024080


1 Answers

If you are using the shortcut post method, you omit the configuration parameter making the first parameter the url.

Since you passed in a configuration object instead of the url as the first parameter, you are getting the error.

$http.post(
  '/api/family', 
  vm.form, 
  {headers: {'Content-Type': 'application/x-www-formurlencoded'}}
).success(function(data) {
    console.log( 'data', data );
})

if you are using the straight http, then you can pass config object :

$http({
    method: 'POST',
    url: 'api/family',
    data : vm.form,
    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data) {
    console.log( 'data', data );
})
like image 178
swestner Avatar answered Jul 30 '26 09:07

swestner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!