0

So I have my post logic:

var data = new FormData();

this.fields.forEach(field => data.append(field.question, field.answer));

console.log(data);

this.http
    .fetch('login', {
        method: 'POST',
        body: data
    })
    .then(response => response.json())
    .then(loginResult => {
        
    });

The console.log shows the object with the correct information in it!

So I'm happy with the data being populated.

The request payload is this:

------WebKitFormBoundaryM4BOxXFW0i3zM4SY
Content-Disposition: form-data; name="passcode"

mysecretpasscode
------WebKitFormBoundaryM4BOxXFW0i3zM4SY--

Which the owin backend doesn't understand:

var form = await c.Request.ReadFormAsync();

c being the OwinContext. The output of form is one entry, with all that payload text in.

Clearly it is trying to send multipart/form-data when I want application/x-www-form-urlencoded

What am I miss configuring here?

Edit - based on possible duplicate

I tried to use that solution but it didn't solve my problem.

Community
  • 1
  • 1
Callum Linington
  • 13,662
  • 12
  • 67
  • 145
  • Possible duplicate of [Post 'x-www-form-urlencoded' content with aurelia-fetch-client](http://stackoverflow.com/questions/36067757/post-x-www-form-urlencoded-content-with-aurelia-fetch-client) – Fabio Luz May 25 '16 at 20:45

1 Answers1

0

Your question is almost the same as this one Post 'x-www-form-urlencoded' content with aurelia-fetch-client, so I'm mostly copying and pasting here...

Instead of sending a FormData object, try to send an object as query-strings, and set the content-type to type application/x-www-form-urlencoded. Like this:

//jQuery.param returns something like ?param=1&param2=2 and so on
//params = a plain javascript object that contains the parameters to be sent
this.http.fetch(url, {
  body: $.param(params),
  method: 'post',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
})
.then(response => response.json())
.then(response => { 
   //your magic here
});

Not a good solution, I know, but that's the easiest way I found so far.

Community
  • 1
  • 1
Fabio Luz
  • 11,714
  • 1
  • 24
  • 40