0
サーバーにPOST要求を出そうとしています。私はGitのバッシュを使ってカール、次の作品:C#のHttpWebRequestでサーバーにCURL POST要求を行う
curl -X POST -H "Content-Type: application/octet-stream" -H "User-Agent: MyUserAgent" --data-binary @MyDocument.xlsx http://myUrl.com
は、私は(C#で)次のようにJSONを使ってPOSTリクエストを行うことができます知っている:
はHttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUrl);
request.Method = "POST";
request.ContentType = "application/json";
request.Accept = "application/json";
request.UserAgent = myUserAgent;
using (var stream = await request.GetRequestStreamAsync())
{
using (StreamWriter streamWriter = new StreamWriter(stream))
{
streamWriter.Write(myJsonData);
}
}
using (HttpWebResponse webResponse = (HttpWebResponse) await request.GetResponseAsync())
{
using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
{
string response = reader.ReadToEnd();
//do stuff with response
}
}
私の難易度は基本的に2つを組み合わせています。私はrequest.ContentTypeを "application/octet-stream"に変更する必要があることを知っていますが、それだけでは不十分です。 HttpWebRequestに "--data-binary @ MyDocument.xlsx"をどのように組み込むのですか? 誰もが考えている?ありがとう!