0
我有以下CURL命令,我想将其转换为C#webapi调用。对C#web api请求的curl命令
curl -H "Content-Type: application/x-www-form-urlencoded" \
-H "client_id: YOUR-CLIENT-ID" \
-H "client_secret: YOUR-CLIENT-SECRET" \
-d "mailbox_id=YOUR-MAILBOX-ID" \
--data-urlencode [email protected]/path/to/email/contents.eml \
"https://api.abc.com/v2/add"
我需要帮助的部分是如何添加邮箱ID和数据作为URL编码。它也从磁盘中获取电子邮件。我可以只添加字节数组吗?
这是我的C#代码的例子。 我只需要在那里添加mailid和电子邮件内容。
public static string WebRequestWithByte(byte[] postData)
{
var url = @"https://api.abv.com/v2/add";
var clientId = "wewew";
var clientSecret = "df58ffed4bc0bc41";
string ret = string.Empty;
StreamWriter requestWriter;
var webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
if (webRequest != null)
{
webRequest.Headers.Add("client_id", clientId);
webRequest.Headers.Add("client_secret", clientSecret);
webRequest.Method = "POST";
webRequest.ServicePoint.Expect100Continue = false;
webRequest.Timeout = 20000;
webRequest.ContentType = "application/x-www-form-urlencoded";
//POST the data.
using (requestWriter = new StreamWriter(webRequest.GetRequestStream()))
{
requestWriter.Write(payloadStr);
}
}
可能式两份http://stackoverflow.com/questions/35463199/how-to-call-a-rest-web-api-for-access-token-with-these-curl-commands-in -c-shar –
@SouvikGhoshSorry它不是。你所建议的是在代码中使用curl.exe的curl例子。我正在寻找转换成C#web API调用。 –