我正在尝试使用Curl从Artifactory下载。zip文件。我使用
System.Diagnostics.Process()
是否有一种方法可以看到下载进展的程度,或者是否有比我使用的方法更好的方法从Artifactory获得.zip文件?这是我正在使用的代码,感谢任何建议的改进
System.Diagnostics.Process process = new System.Diagnostics.Process()
{
StartInfo = new System.Diagnostics.ProcessStartInfo()
{
FileName = "curl",
Arguments = "-H "X-JFrog-Art-Api:<Token>" -X GET "" + url + "" -O "" + path + """,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
}
};
process.Start();
System.IO.StreamReader reader = process.StandardOutput;
string output = reader.ReadToEnd();
process.WaitForExit();
你应该像这样使用HttpClient和HttpRequestMessage:
(https://stackoverflow.com/a/40707446/8800752)string baseURL = "";
string path = "";
string token = "";
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri(baseURL);
using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, path))
{
requestMessage.Headers.Add("X-JFrog-Art-Api", token);
var response = client.Send(requestMessage);
}
}
你可以将其更改为await + SendAsync,如果你要进行多次调用,使用HttpFactory或使客户端静态