我正在使用Newtonsoft尝试序列化一些JSON来执行HttpWebRequest POST
我一直在回复说“错误请求”
我假设我的JSON格式不正确。以下是我的代码
任何帮助非常感谢
Account account = new Account();
account.Name = "TESTACCOUNT";
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://app01.nutshell.com/api/v1/json");
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "POST";
httpWebRequest.Credentials = new NetworkCredential("username", "password");
var serializer = new JsonSerializer();
using (var tw = new Newtonsoft.Json.JsonTextWriter(streamWriter))
{
serializer.Serialize(tw,
new
{
method = "newAccount",
@params = account
});
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
答案 0 :(得分:1)