Increment object to HTTP request

Asked

Viewed 62 times

0

I am trying to make a request in which I send a JSON (POST) and receive another, I am doing the following: 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 the Json (or object) I previously mounted in this request?

1 answer

1


Capture the request stream and write your JSON on 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);

Browser other questions tagged

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