RestSharp从cURL请求的POST请求转换 [英] RestSharp POST request translation from cURL request

查看:647
本文介绍了RestSharp从cURL请求的POST请求转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用RestSharp在JIRA中创建一个问题的POST请求,我需要使用的是一个使用cURL的示例。我不知道我做错了什么。

I'm trying to make a POST request using RestSharp to create an issue in JIRA, and what I have to work with is an example that uses cURL. I'm not familiar with either enough to know what I'm doing wrong.

这里是 example 在cURL中给出:

Here's the example given in 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:

And here's what I'm attempting with 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);

我得到的回应是

Unsupported Media Type

注意:是在此帖中建议的,但是没有解决此问题。欢迎任何指导!

Note: I also tried what was suggested in this post, but that did not resolve the issue. Any guidance is appreciated!

推荐答案

不要

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

而不要尝试:

request.AddBody(issueToCreate);

这篇关于RestSharp从cURL请求的POST请求转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆