【发布时间】:2022-11-21 07:34:48
【问题描述】:
我正在尝试翻译以下 curl 命令
curl --location --request GET "https://xxx.xxxx.xxx/artifacts?session=016e1f70-d9da-41bf-b93d-80e281236c46&path=/home/gauntlet_gameye/LinuxServer/Game/Saved/Logs/Game.log" -H "Authorization:Bearer xxxx" -H "Accept:application/json" --output C:\Temp\Game.log
对于 C# 代码,我有以下内容
string SessionId = "016e1f70-d9da-41bf-b93d-80e281236c46";
string Token = "xxxx";
string FilePath = "/home/gauntlet_gameye/LinuxServer/Game/Saved/Logs/Game.log";
string Endpoint = string.Format("https://xxx.xxxx.xxx/artifacts?session={0}&path={1}", SessionId, FilePath);
HttpRequestMessage HttpRequestMsg = new HttpRequestMessage();
HttpRequestMsg.RequestUri = new Uri(Endpoint);
HttpRequestMsg.Method = HttpMethod.Get;
HttpRequestMsg.Headers.Add("Accept", "application/json");
HttpRequestMsg.Headers.Add("Authorization", string.Format("Bearer {0}", Token));
HttpRequestMsg.Content = new StringContent(string.Format("--output {0}", OutFilePath), Encoding.UTF8, "application/json");
using (HttpClient Client = new HttpClient())
{
var HttpResponseTask = Client.SendAsync(HttpRequestMsg);
}
但它给了我以下异常信息
Cannot send a content-body with this verb-type.
【问题讨论】:
-
嗯,
--output C:\Temp\Game.log是对 curl 应用程序的指示,说明它应该将响应通过管道传输到哪个文件。它不是请求正文(这是您尝试使用HttpRequestMsg.Content执行的操作)。 -
@ProgrammingLlama 好的,那应该怎么做呢?
-
您读取响应并将其写入文件。
-
啊,对不起,好的,我明白了,谢谢。
标签: c# curl httprequest