0

It seems I can post a json object in the body with no trouble and bind it via [FromBody]. I can also post the header and bind it with [FromHeader(Name=...)]. But I can't use them together. Anyone know how or have another way of binding ether?

my Controller action method looks like this:

public JsonResult ProductQuery([FromHeader(Name = "Authorization")]string value, [FromBody] Product product)

When I do this I get the header in value but I don't get the body, I get a null in product

Thanks for your help!

Irv Lennert
  • 555
  • 5
  • 20
  • 1
    One way would be : http://stackoverflow.com/a/21405101/1129995 – Zaki Mar 31 '16 at 08:16
  • Maybe this can help http://stackoverflow.com/a/31460183/3645004 – shashank Mar 31 '16 at 08:40
  • 1
    Thanks for the references. There is no problem with bring in the header and body as I show. The problem is Angular 2 sends the wrong content type when sending header info. – Irv Lennert Mar 31 '16 at 16:02

1 Answers1

1

The link below gave me the best hint but his solution was jQuery.

There is no problem with bringing in the header and body as I show. The problem is Angular 2 sends the wrong content type when sending header info. I had to do this in angular 2 on the client side. Note the 'Content-Type' line:

    var headers = new Headers();
    headers.append('Authorization', 'Bearer ' + localStorage.getItem('id_token'));
    headers.append('Content-Type', 'application/json');
    return this._http.post('/api/orderProdListQuery', JSON.stringify(query), { headers: headers })

how-to-pass-json-post-data-to-web-api-method-as-object

Community
  • 1
  • 1
Irv Lennert
  • 555
  • 5
  • 20