【发布时间】:2019-12-27 16:36:57
【问题描述】:
我只在 C# 中得到代码 400,而当我使用邮递员时,我得到 200! 它具有相同的属性。
我最初将这些类创建为 JSONProperty 属性,但在分散后仍然得到代码 400。
在提琴手内发现异常 - message=parameters:“XXXXX.AzureAd.XXX.Types.NewDescriptionEntry”类型上不存在属性“Changedby”。确保仅使用类型定义的属性名称。
// Serialize our concrete class into a JSON String
var stringPayload = await Task.Run(() =>
JsonConvert.SerializeObject(payload_transferIncident));
// build the URL we'll hit
var url = string.Format("https://XXXXXX", "YYYYY", id, "XXXX");
//create the request
var req = HttpWebRequest.CreateHttp(url);
//add in the cert we'll authenticate with
req.ClientCertificates.Add(IcmIncidentOperation.GetCert("XXXXXX"));
req.ContentType = "application/json";
req.Method = "POST";
if (req == null)
throw new ApplicationException(string.Format("Could not create the httprequest from the url:{0}", url));
try
{
using (var streamWriter = new StreamWriter(req.GetRequestStream()))
{
streamWriter.Write(stringPayload);
}
var httpResponse = (HttpWebResponse)req.GetResponse();
}
catch (Exception ex)
{
Console.WriteLine(ex);
var httpResponse = (HttpWebResponse)req.GetResponse();
}
【问题讨论】:
-
我鼓励您调试此代码,您会立即看到您没有向请求流写入任何内容。您打算将
payload_transferIncident的序列化结果写入其中,但您的代码并未将其分配给任何变量,它只是将其丢弃。
标签: c# http post httpwebrequest