gpt4 book ai didi

c# - 如何在 ServiceStack 客户端中设置 ContentType?

转载 作者:太空宇宙 更新时间:2023-11-03 13:43:51 25 4
gpt4 key购买 nike

我正在使用 ServiceStack 客户端调用网络服务,如下所示:

var client = new JsonServiceClient(apiUrl);
var url = "/V1/MyApiCall";

var response = client.Post<MyApiCallResponse>(url, "foo=" + request.foo + "&bar=" + request.bar);

这通常效果很好,但我需要更改 Content-Type header 。默认情况下(对于我从该服务进行的大多数其他调用)这需要是 application/json,但在这种特殊情况下它需要是 application/x-www-form- urlencoded.

client.ContentType 没有实现 setter,那么如何更改 Content-Type header ?

最佳答案

不要使用 Servicestack's C# Clients调用第 3 方 API。您正在使用按预期发送 JSON 的 JSON 客户端。您可以使用 ServiceStack's built-in HTTP Utils如果您需要调用 3rd Party API,请查看 POSTing data examples ,例如:

var response = url.PostToUrl(new { foo = request.foo, bar = request.bar },
acceptContentType = "application/json")
.FromJson<MyApiCallResponse>();

关于c# - 如何在 ServiceStack 客户端中设置 ContentType?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15999769/

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