How to send json to Web Service

Hello, i have a big problem. I need to use this web service: https://static.anaf.ro/static/10/Anaf/Informatii_R/documentatie_SWAsincron_01112017.txt

But they have so small documentation about it that i don’t really understund what should i send. I tried to send a request like this:

    System.Net.WebRequest webreq = System.Net.WebRequest::Create("https://webservicesp.anaf.ro:/PlatitorTvaRest/api/v1/ws/tva");
    System.IO.Stream streamstr,responsestr;
    System.IO.StreamWriter streamWriter;
    System.Net.WebResponse webresponse;
    System.IO.StreamReader reader;
    System.Exception ex;

    str json = "{\"cui\":\" customerVatNumber\"," +
                  "\"data\":\"2018-03-07\"}";

   webreq.set_Method("POST");
   webreq.set_ContentType("application/json");
   streamstr = webreq.GetRequestStream();
   streamWriter = new System.IO.StreamWriter(streamstr);
   streamWriter.Write(json);
   streamWriter.Flush();
   streamWriter.Close();
   streamWriter.Dispose();

    try
    {
       webresponse = webreq.GetResponse();
       responsestr = webresponse.GetResponseStream();
       reader = new System.IO.StreamReader(responsestr);
       info(reader.ReadToEnd());
    }
    catch(Exception::CLRError)
    {
            ex = ClrInterop::getLastException();
            if (ex != null)
            {
                ex = ex.get_InnerException();
                if (ex != null)
                {
                    error(ex.ToString());
                }
            }
    }

But i have error about “unsupported media type”.

Can you help me? What is the best practice to consume Web Service via x++?

Thanks allot!

Doesn’t the service documentation say that the request should be an array (i.e. wrapped in [])?
By the way, I wouldn’t like to escape every quotation mark in the JSON string. Consider using single quotes for the string literal. Also note that verbatim strings (prefixed with @) can span several lines.

Can you look at this documentation? They don’t even write how should i call the parameters :confused:
I tried to pass them in array, by parts. But nothing works

If “this documentation” means the link in your original question, that’s what I did look at. What else did you mean that I was talking about?

Unfortunately I don’t speak Romanian and you didn’t provide any translation, but this look like an example of expected parameters, which doesn’t match what you’re sending:

Request-ul trebuie sa fie trimis prin POST iar formatul este similar cu exemplul de mai jos:

Content-Type: application/json
[
    {
        "cui": 1234,
        "data": "2015-02-14"
    },
    {
        "cui": 5678,
        "data": "2015-02-14"
    }
]