我正在使用C#中的HttpClient向Webapi端点发送JSON LD数据。我收到错误,不支持的媒体类型格式化程序。我发送的数据是JSONLD作为字符串:
string data = @"{
""@type"": ""vcx:blah"",
""vcx:key"": ""blah"",
""vcx:value"": ""blah""
} ";
httpClient.PostAsync(uri, new StringContent(data));
在api方面,是网络api。在Global.asax.cs中,我具有以下内容:
GlobalConfiguration.Configuration.Formatters.Clear();
GlobalConfiguration.Configuration.Formatters.Add(new
JsonMediaTypeFormatter());
即使删除了格式化程序的清除,我在调用应用程序时也会遇到相同的错误。
有人知道解决方案吗?
请参见docs
您正在使用StringContent
的第一个构造函数,这意味着创建的StringContent
的媒体类型默认为StringContent
如果需要jsono,请指定媒体类型:
text/plain