HTML Json POST C#

Asked

Viewed 85 times

0

I have the following class:

public class Ticket
{
    public string name { get; set; }

    public string content { get; set; }

    public int itilcategories_id { get; set; }

}

And the next task:

static async Task<Uri> CreateTicketAsync()
{
client.DefaultRequestHeaders.Clear();

List<Ticket> tickets = new List<Ticket>();
tickets.Add(ticket);

var parametro = new
{
     input = tickets.ToArray()
 };

 var jsonContent = JsonConvert.SerializeObject(parametro);
 var contentString = new StringContent(jsonContent, Encoding.UTF8, "application/json");

 contentString.Headers.ContentType = new MediaTypeHeaderValue("application/json");
 contentString.Headers.Add("Session-Token", session_token);

 HttpResponseMessage response = await client.PostAsync("apirest.php/Ticket/", contentString);

            return response.Headers.Location;
 }

The content of the ticket is passed HTML, but it is converted to JSON so it can be sent by the Post, which makes it not appear correctly on the website to which it is sent. Does anyone know how to solve the problem?

inserir a descrição da imagem aqui

The n that appear above should not appear and between those categories there should be paragraph.

HTML: before being converted

<!DOCTYPE html><html xmlns=\"\"http://www.w3.org/1999/xhtml\"\">\r\n<head>  \r\n<meta http-equiv=\"\"Content-Type\"\" content=\"\"text/html; charset=utf-8\"\"><style type=\"\"text/css\"\"> body,p,td {{font-size:9.0pt;line-height:115%; color:#595959 ;line-height:115%;font-family:'Arial','sans-serif';}}</style> \r\n</head><body><p>Foi recebida a seguinte informacao relativa a umasubscricao JASMIN:</p><br>\r\n<b>Utilizador CIS: </b>{1}</p><b>Nome: </b>{0}</p><b>Morada: </b>{2}</p><b>Codigo Postal: </b>{3}</p><b>NIF: </b>{4}</p><b>Email: </b>{5}</p><b>Parceiro: </b>{6}</p><br>\r\n<br><b>Subscricao Ant: </b>{7}</p><b>Contrato CIS Ant: </b>{8}</p><br>\r\n<br><b>Solucao: </b>{9}</p><b>Subscricao: </b>{10}</p><b>Contrato CIS: </b>{11}</p><b>Inicio: </b>{12}</p><b>Fim: </b>{13}</p><b>Pagamento: </b>{14} {15}</p><b>Ref MB: </b>{16}</p><br>\r\n</body></html>",

Any questions, let me know!

  • and which string is converted after ?

  • string x = "seu html"; x = x.Replace("\r","").Replace("\n","<br>"); ?

  • paragraph in json ? , the formatting you do on the page, in html...

  • yes, json does not need to have a paragraph, json has data. Where you display this data, you format as you wish...

  • yes, it is irrelevant to have line breaks in json, formatting should be done when it is displayed to the user

  • Okay, thanks for the help

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.