2013-12-19 44 views
0

如何將JSON數據發佈到.net請求的正文?如何將JSON數據發佈到.net請求的正文?

我正在使用.net 2010,顯然thr httpclient不適用於我。我將數據轉換爲JSON,現在需要將其發佈到Ruby api,並且他們希望將其發佈到正文中。

+0

你在使用任何特定的庫嗎? RestSharp?它允許你在正文中指定數據。 – Swati

回答

0

如果你沒有使用任何特定的庫,你應該能夠使用System.Net.WebClient。 下面是一個例子:

var wc = new WebClient(); 
wc.Headers.Add("Content-Type", "application/json; charset=utf-8"); 
var result = wc.UploadString("http://your/api/url", "POST", your_json_string); 

假設your_json_stringstring變量中包含您的JSON格式的數據。

相關問題