Hi,
This is in Build 5447.
I'm trying to POST to an API and getting a 415 Unsupported Media Type as a response. I am able to GET from the API using basic auth, but the POST is having issues because (I think) I am not setting the Content-Type.
My question is how do I set two headers?
I am setting the auth as follows and that works great for GET:
But how do I append the Content-Type to _settings.header?
I've tried the following so far:
If I reverse it (content-type first)
I get a 401 (Unauthorized access), so that tells me the basic auth isn't getting to the server.
For the heck of it, I tried setting Content-Type like this, but no go.
Thanks!
This is in Build 5447.
I'm trying to POST to an API and getting a 415 Unsupported Media Type as a response. I am able to GET from the API using basic auth, but the POST is having issues because (I think) I am not setting the Content-Type.
Code:
HTTP/1.1 415 Unsupported Media Type Access-Control-Allow-Headers: Content-Type,Authorization Access-Control-Allow-Methods: POST,GET,PUT,DELETE,HEAD,OPTIONS Access-Control-Allow-Origin: * Cache-Control: no-cache Content-Type: application/json; charset=utf-8 Date: Sat, 10 Nov 2018 00:16:17 GMT Expires: -1 Pragma: no-cache Server: Microsoft-IIS/8.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Content-Length: 997 Connection: Close {"Message":"The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource.","ExceptionMessage":"No MediaTypeFormatter is available to read an object of type 'ApiConstituentModel' from content with media type 'application/octet-stream'.","ExceptionType":"System.Net.Http.UnsupportedMediaTypeException","StackTrace":" at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)"}
I am setting the auth as follows and that works great for GET:
Code:
_settings.header = "Authorization: Basic " + _myApiKey
I've tried the following so far:
Code:
_settings.header = _settings.header+" Content-Type: application/json" _settings.header = _settings.header+"[COLOR="#FF0000"]&[/COLOR]Content-Type: application/json" _settings.header = _settings.header+"[COLOR="#FF0000"];[/COLOR]Content-Type: application/json" response = http_fetch(_settings)
Code:
_settings.header = "Content-Type: application/json " + _settings.header _settings.header = "Content-Type: application/json&" + _settings.header _settings.header = "Content-Type: application/json;" + _settings.header
For the heck of it, I tried setting Content-Type like this, but no go.
Code:
_settings.content_type = "application/json"
Comment