私はC#webapi呼び出しに変換したいCURLコマンドを以下に示します。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#コードの例があります。 メールIDと電子メールの内容をそこに追加するだけです。
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);
}
}
可能duplicate- http://stackoverflow.com/questions/35463199/how-to-call-a-rest-web-api-for-access-token-with-these-curl-commands-in -c-shar –
@SouvikGhosh申し訳ありません。あなたが示唆したのは、curl.exeをコードで使用したカールの例です。私はそれをC#のWeb APIの呼び出しに変換するために探しています。 –