gpt4 book ai didi

c# - System.Net.Http.Formatting 的 PostAsJsonAsync 在 Xamarin PCL 上抛出 System.NotImplementedException

转载 作者:行者123 更新时间:2023-11-30 00:22:08 24 4
gpt4 key购买 nike

HttpClient client = new HttpClient();
client.BaseAddress = uri;
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

HttpResponseMessage response = client.PostAsJsonAsync(route, requestResource).Result;

不使用 Xamarin PCL 并导致此错误:

ex = {System.TypeInitializationException: The type initializer for 'System.Net.Http.FormattingUtilities' threw an exception. ---> System.NotImplementedException: The method or operation is not implemented.
at System.Runtime.Serialization.XsdDataContractExporte...

最佳答案

老实说,我没有使用过那个方法,但它没有实现,所以也没什么可做的。

虽然你可以这样发帖

var request = new HttpRequestMessage(HttpMethod.Post, route);
var hc = new StringContent(requestResource); // requestResource should be a string
hc.Headers.ContentType = new MediaTypeHeaderValue("application/json);
request.Content = hc;
var response = await httpClient.SendAsync(request);

关于c# - System.Net.Http.Formatting 的 PostAsJsonAsync 在 Xamarin PCL 上抛出 System.NotImplementedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46076037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com