使用操作
var result = await XiaoFeng.Http.HttpHelper.GetHtmlAsync(new XiaoFeng.Http.HttpRequest
{
Method = HttpMethod.Get,//不设置默认为Get请求
HttpCore = HttpCore.HttpClient,//不设置默认为HttpClient内核
Address = "https://www.eelf.cn"
});
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
/*请求成功*/
//响应内容
var value = result.Html;
//响应内容字节集
var bytes = result.Data;
}
else
{
/*请求失败*/
}
//第二种用法
var result = await new HttpRequest{
Method = HttpMethod.Get,
Address = "https://www.eelf.cn"
}.GetResponseAsync();
//第三种用法
var result = await new HttpRequest("https://www.eelf.cn").SetMethod(HttpMethod.Get).GetResponseAsync();
var result = await XiaoFeng.Http.HttpHelper.GetHtmlAsync(new XiaoFeng.Http.HttpRequest
{
Method = HttpMethod.Post,
Address = "http://www.fayelf.com",
Data = new Dictionary<string, string>
{
{"account","jacky" },
{"password","123456" }
}
});
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
/*请求成功*/
//响应内容
var value = result.Html;
//响应内容字节集
var bytes = result.Data;
}
else
{
/*请求失败*/
}
var result = await XiaoFeng.Http.HttpHelper.GetHtmlAsync(new XiaoFeng.Http.HttpRequest
{
Method = HttpMethod.Post,
ContentType = "application/json",
Address = "https://www.eelf.cn",
BodyData = @"{""account"":""jacky"",""password"":""123456""}"
});
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
/*请求成功*/
//响应内容
var value = result.Html;
//响应内容字节集
var bytes = result.Data;
}
else
{
/*请求失败*/
}
- POST FORMDATA 请求,就是有表单输入数据也有文件流数据
var result = await XiaoFeng.Http.HttpHelper.GetHtmlAsync(new XiaoFeng.Http.HttpRequest
{
Method = HttpMethod.Post,
ContentType = "application/x-www-form-urlencoded",
Address = "https://www.eelf.cn",
FormData = new List<XiaoFeng.Http.FormData>
{
new XiaoFeng.Http.FormData
{
Name="account",Value="jacky", FormType= XiaoFeng.Http.FormType.Text
},
new XiaoFeng.Http.FormData
{
Name="password",Value="123456",FormType= XiaoFeng.Http.FormType.Text
},
new XiaoFeng.Http.FormData
{
Name="headimage",Value=@"E://Work/headimage.png", FormType= XiaoFeng.Http.FormType.File
}
}
});
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
/*请求成功*/
//响应内容
var value = result.Html;
//响应内容字节集
var bytes = result.Data;
}
else
{
/*请求失败*/
}
await XiaoFeng.Http.HttpHelper.Instance.DownFileAsync(new XiaoFeng.Http.HttpRequest
{
Method = HttpMethod.Get,
Address = "https://www.eelf.cn/test.rar"
}, @"E:/Work/test.rar");