110,534
社区成员
发帖
与我相关
我的任务
分享
//请求示例:
//curl -u 账号:密码 -H "Accept: application/json" -X POST -H "Content-Type: application/x-www-form-urlencoded" -d parentId=父文件夹ID -d path=文件夹名称
// url 为请求地址,也就是curl指向的地址
HttpWebRequest http = (HttpWebRequest)WebRequest.Create(url);
// -H 表示http请求中需要有一个Header信息
// -H "Accept: application/json"
http.Accept = "application/json";
// -u 账号:密码,提交身份验证信息
http.Headers.Add("Authorization","Basic " + Convert.ToBase64String(Syste.Text.Encoding.UTF8.GetBytes("账号:密码")));
// -X POST 使用 POST 方式请求
http.Method = "POST";
// -d 表示提交的表单中的信息
// -d parentId=父文件夹ID
byte[] pd = null;
string QueryString = "parentId=父文件夹ID"; // 如果有多个 -d ,用 & 拼接每一个参数
pd = new UTF8Encoding().GetBytes(QueryString);
http.ContentLength = pd.Length;
Stream ps = http.GetRequestStream();
ps.Write(pd, 0, pd.Length); // 将表单请求写入到请求头中
ps.Close();
ps.Dispose();
NetworkCredential networkCredential=new NetworkCredential(UserName,Password);
http.Credentials=networkCredential;
using (Process myPro = new Process())
{
//指定curl存放的路径
myPro.StartInfo.FileName = @"C:\curl.exe";
myPro.StartInfo.UseShellExecute = false;
myPro.StartInfo.RedirectStandardInput = true;
myPro.StartInfo.RedirectStandardOutput = true;
myPro.StartInfo.RedirectStandardError = true;
myPro.StartInfo.CreateNoWindow = true;
//该命令(-I)只显示请求头信息
myPro.StartInfo.Arguments = "-I http://www.baidu.com";
myPro.Start();
myPro.StandardInput.AutoFlush = true;
//获取cmd窗口的输出信息
string output = myPro.StandardOutput.ReadToEnd();
myPro.WaitForExit();
myPro.Close();
Console.WriteLine(output);
}