We\'ve got a .net WebAPI which looks for a filepath string in the body of a post request and returns the corresponding image. I\'m struggling to successfully pass a string t
There is almost everything good with your code. Main issue is Content-Type
header. If you want to send string to .NET
REST API with [FromBody]
annotation and use application/json
header value you should add ""
to your path param for example "test_value"
:
return this.http.post(
`${apiUrl}`,
`\"${path}\"` ,
{ headers: new HttpHeaders({
'Content-Type': 'application/json',
}), responseType: 'blob',
})
You can also use x-www-form-urlencoded
header value. Then you must pass your param to request body in that way:
return this.http.post(
`${apiUrl}`,
`=${path}` ,
{ headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded',
}), responseType: 'blob',
})