StarsFlyFree FromCozyNights StarsFlyFree FromCozyNights - 3 months ago 37
C# Question

Make POST() With JSON

I am learning JSON and can not figure out the next step. I have created a JSON Reader and have added the data I need to into my reader, but how do I now actually make a POST() request with the data?

This is what I have

private void PerformJSONPost()
var httpWebRequest = (HttpWebRequest)WebRequest.Create("");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";

var jsonReader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(@"{ ""Security"": { ""UsernameToken"": { ""Username"": ""redrobin"", ""Password"": ""fahidsma!"" } }"), new System.Xml.XmlDictionaryReaderQuotas());



The issue with this syntax is that the only thing that is posted is:


        var request = WebRequest.CreateHttp(myUrl + "/" + uri);
        request.Credentials = new NetworkCredential(myUserName, myPassword, myDomain);
        request.ContentType = "application/json; charset=utf-8";
        request.Method = "POST";

        using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream()))
            string jsonstring = JsonConvert.SerializeObject(myJsonobject, Formatting.Indented);



have look above