gpt4 book ai didi

c# - RestSharp POST 请求从 cURL 请求转换

转载 作者:行者123 更新时间:2023-11-30 14:34:47 24 4
gpt4 key购买 nike

我正在尝试使用 RestSharp 发出 POST 请求以在 JIRA 中创建问题,而我必须使用的是一个使用 cURL 的示例。我对两者都不熟悉,无法知道自己做错了什么。

这是 example在 cURL 中给出:

curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json"
http://localhost:8090/rest/api/2/issue/

这是他们的示例数据:

{"fields":{"project":{"key":"TEST"},"summary":"REST ye merry gentlemen.","description":"Creating of an issue using project keys and issue type names using the REST API","issuetype":{"name":"Bug"}}}

下面是我在 RestSharp 上的尝试:

RestClient client = new RestClient();
client.BaseUrl = "https://....";
client.Authenticator = new HttpBasicAuthenticator(username, password);
....// connection is good, I use it to get issues from JIRA
RestRequest request = new RestRequest("issue", Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("data", request.JsonSerializer.Serialize(issueToCreate));
request.RequestFormat = DataFormat.Json;
IRestResponse response = client.Execute(request);

我得到的是

的 415 响应
Unsupported Media Type

注意:我还尝试了 this post 中的建议, 但这并没有解决问题。任何指导表示赞赏!

最佳答案

不要做

request.AddParameter("data", request.JsonSerializer.Serialize(issueToCreate));

改为尝试:

request.AddBody(issueToCreate);

关于c# - RestSharp POST 请求从 cURL 请求转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13380845/

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