Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misused header 'content-type' Async #4

Open
Sven286 opened this issue Sep 24, 2024 · 2 comments
Open

Misused header 'content-type' Async #4

Sven286 opened this issue Sep 24, 2024 · 2 comments

Comments

@Sven286
Copy link

Sven286 commented Sep 24, 2024

Hi,

I just started to use this nuget package for connecting to the api of my zabbix 6.0.23 installation.
I created my new project as .Net 8 application and want to use asynchrone methods.
Receiving all host groups gives me the following exception.

var groups = await _zabbixCore.HostGroups.GetAsync()

System.InvalidOperationException: Misused header name, 'content-type'. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
   at System.Net.Http.Headers.HttpHeaders.GetHeaderDescriptor(String name)
   at System.Net.Http.Headers.HttpHeaders.Add(String name, String value)
   at Zabbix.Core.ZabbixCore.SendRequestAsync[T](Object params, String method, String token)
   at Zabbix.Core.ZabbixCore.SendRequestAsync[T](Object params, String method)
   at Zabbix.Services.CrudServices.GetService`2.GetAsync(TEntityFilter filter)
   at Zabbix.Services.CrudServices.CrudService`3.GetAsync(TEntityFilter filter)

When I call the method synchroniously everything works fine.
var groups = _zabbixCore.HostGroups.Get()

I Suspect the following line of code to be the issue, but I don't know why this piece is added:

_httpClient.DefaultRequestHeaders.Add("content-type", "application/json-rpc");

@stefan-epic
Copy link
Owner

I will look into this when I get the time thanks for making the issue :)

@Scriptman
Copy link

Scriptman commented Dec 11, 2024

Just remove the line 134 in ZabbixCore.cs:
this._httpClient.DefaultRequestHeaders.Add("content-type", "application/json-rpc");

It's in the SendRequestAsync(object? @params, string method, string? token) method.

You don't use this in the non-Async request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants