๋๊ตฐ๊ฐ๊ฐ ์์ฒญ ๋งค๊ฐ๋ณ์๋ก ์๋๋ฅผ ์ฌ์ฉํ์ฌ HTTP Post๋ฅผ ๋ณด๋ด๋ ๋ฐฉ๋ฒ์ ๋ํด ์กฐ์ธํด ์ฃผ์๊ฒ ์ต๋๊น?
{
"key": "example key",
"message": {
"html": "<p>Example HTML content</p>",
"text": "Example text content",
"subject": "example subject",
"from_email": "[email protected]",
"from_name": "Example Name",
"to": [
{
"email": "[email protected]",
"name": "Recipient Name"
}
],
"headers": {
"Reply-To": "[email protected]"
},
"important": false,
"track_opens": null,
"track_clicks": null,
"auto_text": null,
"auto_html": null,
"inline_css": null,
"url_strip_qs": null,
"preserve_recipients": null,
"view_content_link": null,
"bcc_address": "[email protected]",
"tracking_domain": null,
"signing_domain": null,
"return_path_domain": null,
"merge": true,
"global_merge_vars": [
{
"name": "merge1",
"content": "merge1 content"
}
],
"merge_vars": [
{
"rcpt": "[email protected]",
"vars": [
{
"name": "merge2",
"content": "merge2 content"
}
]
}
],
"tags": [
"password-resets"
],
"subaccount": "customer-123",
"google_analytics_domains": [
"example.com"
],
"google_analytics_campaign": "[email protected]",
"metadata": {
"website": "www.example.com"
},
"recipient_metadata": [
{
"rcpt": "[email protected]",
"values": {
"user_id": 123456
}
}
],
"attachments": [
{
"type": "text/plain",
"name": "myfile.txt",
"content": "ZXhhbXBsZSBmaWxl"
}
],
"images": [
{
"type": "image/png",
"name": "IMAGECID",
"content": "ZXhhbXBsZSBmaWxl"
}
]
},
"async": false,
"ip_pool": "Main Pool",
"send_at": "example send_at"
}
RestSharp๋ฅผ ์ฌ์ฉํ์ฌ ์ด ์์ ์ ์ํํ๋ ๋ฐฉ๋ฒ์ ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
์๋ ,
1) JSON์ POCO๋ก ๋ณํํฉ๋๋ค(http://json2csharp.com/์ด ์ ํฉํฉ๋๋ค).
2)
var yourobject = new MyObject{...........};
var json = JsonConvert.SerializeObject(๊ทํ์ ๊ฐ์ฒด);
var ํด๋ผ์ด์ธํธ = ์๋ก์ด RestClient(url);
var ์์ฒญ = ์๋ก์ด RestRequest(actionPath, Method.POST);
์์ฒญ .AddParameter("์์ฉ ํ๋ก๊ทธ๋จ/json; charset=utf-8", json, ParameterType.RequestBody);
์์ฒญ .RequestFormat = DataFormat.Json;
_client.ExecuteAsync(restRequest, ์๋ต => ........);
๋๋ ๊ทธ๋!
ํ์์ ์ํด RestSharp์๋ ํ์ฌ ์ด๋ฅผ ์ํ ๋ด์ฅ ๋ฉ์๋๊ฐ ์์ต๋๋ค.
RestRequest
์ AddJsonBody()
๋ฐฉ๋ฒ์ ํ์ธํ์ญ์์ค.
์ด์จ๋ ์ด๊ฒ์ RestSharp 105.0.1.0 ์ด์์์ ์ ํํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์๋ ,
1) JSON์ POCO๋ก ๋ณํํฉ๋๋ค(http://json2csharp.com/์ด ์ ํฉํฉ๋๋ค).
2)
var yourobject = new MyObject{...........};
var json = JsonConvert.SerializeObject(๊ทํ์ ๊ฐ์ฒด);
var ํด๋ผ์ด์ธํธ = ์๋ก์ด RestClient(url);
var ์์ฒญ = ์๋ก์ด RestRequest(actionPath, Method.POST);
์์ฒญ .AddParameter("์์ฉ ํ๋ก๊ทธ๋จ/json; charset=utf-8", json, ParameterType.RequestBody);
์์ฒญ .RequestFormat = DataFormat.Json;
_client.ExecuteAsync(restRequest, ์๋ต => ........);