Increase object to HTTP request

0

I'm trying to make a request in which I send a JSON (POST) and I get another one, I'm doing the following: I mount / feed my object and call this request:

string URLRequest = URL + customer_id + "/cards";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Headers.Add("...");
request.Method = "POST";
request.ContentType = "application/json";
request.Accept = "application/json";

My question is: how do I implement in this request the Json (or object) that I previously mounted?

    
asked by anonymous 25.07.2017 / 16:38

1 answer

1

Capture the request stream and write your JSON in it.

var payload = UTF8Encoding.UTF8.GetBytes(seuJson);

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Headers.Add("...");
request.Method = "POST";
request.ContentType = "application/json";
request.Accept = "application/json";

using(var stream = request.GetRequestStream())
    stream.Write(payload, 0, payload.Length);
    
25.07.2017 / 16:45