2016-12-01 91 views
0

我正在學習JSON,無法弄清下一步。我創建了一個JSON閱讀器,並將我需要的數據添加到我的閱讀器中,但是我現在如何使用這些數據實際發出POST()請求?使用JSON POST()

這是我

private void PerformJSONPost() 
{ 
    var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://requestb.in/12frf661"); 
    httpWebRequest.ContentType = "application/json"; 
    httpWebRequest.Method = "POST"; 

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

} 

編輯
這個語法的問題是,被張貼的唯一的事情就是:

System.Runtime.Serialization.Json.XmlJsonReader 

回答

0
 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); 

      streamWriter.Write(jsonstring); 

      streamWriter.Flush(); 
     } 

已經看清楚上面