我在向API发送HTTP Request
时遇到问题。
由于我发送的内容在Internal Server Error 500
中,但应该在Text format
中,因此我一直在使用API从下面的代码接收到JSON format
。我也尝试过JsonConverter.SerializeObject
来转换fileJson
变量,但是它不起作用。
var client = new HttpClient();
var httpRequestMessage = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://some-url"),
Headers = {
{ HttpRequestHeader.Authorization.ToString(), "Bearer " + token},
{ HttpRequestHeader.Accept.ToString(), "application/json" },
{ HttpRequestHeader.ContentType.ToString(), "application/json"},
{ "client-id", "clientid"},
{ "client-secret","clientsecret"},
{ "partner-id","partnerid"},
{ "X-Version", "1" }
},
Content = new StringContent(fileJson)
};
var response = client.SendAsync(httpRequestMessage).Result;
这是fileJson
包含的字符串
{
"senderRefId":"TRANSFER0001",
"tranRequestDate":"2018-08-10T08:40:45.897",
"particulars":"particulars",
"sender":{
"name":"name",
"address":{
"line1":"line1",
"line2":"line2",
"city":"city",
"province":"province",
"zipCode":"zip",
"country":"country"
}
}
我已经在Postman上对其进行了测试,当我的请求正文位于原始JSON format
中时,它可以工作,而当它位于Text format
中时,则出现错误。