gopherr gopherr - 1 year ago 318
C# Question

RestSharp POST request translation from cURL request

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.

Here's the example given in cURL:

curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json"

Here's their example data:

{"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"}}}

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);

What I get back is a 415 response of

Unsupported Media Type

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

wal wal
Answer Source

dont do

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

instead try:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download