【发布时间】:2015-12-05 18:54:59
【问题描述】:
我想在我的应用程序中使用短信网关。所以我联系了运营商,运营商给了我一个api格式。
网址:https://ideabiz.lk/apicall/smsmessaging/v2/outbound/3313/requests
请求头
Content-Type: application/json
Authorization: Bearer [access token]
Accept: application/json
身体
{
"outboundSMSMessageRequest": {
"address": [
"tel:+94771234567"
],
"senderAddress": "tel:12345678",
"outboundSMSTextMessage": {
"message": "Test Message"
},
"clientCorrelator": "123456",
"receiptRequest": {
"notifyURL": "http://128.199.174.220:1080/sms/report",
"callbackData": "some-data-useful-to-the-requester"
},
"senderName": "ACME Inc."
}
}
现在,我已经编码了:
RestClient client = new RestClient(@"https://ideabiz.lk/");
RestRequest req = new RestRequest(@"apicall/smsmessaging/v2/outbound/3313/requests", Method.POST);
req.AddHeader("Content-Type", @"application/json");
req.AddHeader("Authorization", @"Bearer " + accessToken.ToString());
req.AddHeader("Accept", @"application/json");
string jSon_Data = @"{'outboundSMSMessageRequest': {'address': ['tel:+94768769027'],'senderAddress': 'tel:3313','outboundSMSTextMessage': {'message': 'Test Message : " + System.DateTime.Now.ToString() + "'},'clientCorrelator': '123456','receiptRequest': {'notifyURL': 'http://128.199.174.220:1080/sms/report','callbackData': 'some-data-useful-to-the-requester'},'senderName': ''}}";
JObject json = JObject.Parse(jSon_Data);
req.AddBody(json);
IRestResponse response = client.Execute(req);
string x = response.Content.ToString();
Console.WriteLine(x.ToString());
当我执行这个程序时,在行中
req.AddBody(json);
我的系统崩溃并给出错误信息:
System.Windows.Forms.dll 中出现“System.StackOverflowException”类型的未处理异常
如何使用 C#.NET 发布复杂的 JSON?
【问题讨论】: