3
I have the Following class set:
public class Ticket
{
public string name
public string content
public int itilcategories_id
}
And the following code sample:
static HttpClient client = new HttpClient();
client.BaseAddress = new Uri("https://stgsd.primaverabss.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
ticket.name = "TESTE";
ticket.content = "teste";
ticket.itilcategories_id = 1
HttpResponseMessage response = await client.PostAsync("apirest.php/Ticket/", XXXXXXXXX );
My goal is to replace the XXXXXXX that are in Postasync so that in its place you pass the information of the Ticket and when sending to the respective link the content is as follows:
{"input":[{"name": "TESTE", "content": "teste", "itilcategories_id":"1"}]}
Any ideas? Any questions, let us know!!
include your client’s statement
– Leandro Angelo
@idkWhy, Adjusted.
– Leandro Angelo
@Idkwhy, you solved?
– Leandro Angelo
Gives error 400: Bad Request
– IdkWhy
Are you sure that that is the expected model? via Postman, you can perform the operation?
– Leandro Angelo
I use Fiddler and yes I performed the operation
– IdkWhy
I just made one and it came out right
– IdkWhy
Let’s go continue this discussion in chat.
– Leandro Angelo
Pass "application/json" in the Stringcontent constructor and then contentString.Headers.Contenttype = new Mediatypeheadervalue("application/json"); and redundancy, not?
– Aitiow
@Aitiow yes and is purposeful, already happened in some applications, of the variable not being added when presented in the constructor of
StringContent()
. So by habit I always reinforce the Mediatype too– Leandro Angelo