#region Copyright (C) 2016 Kevin (OSS开源系列) 公众号:osscore /*************************************************************************** *   文件功能描述:Http请求 == 请求实体 * *   创建人: Kevin * 创建人Email:1985088337@qq.com * *****************************************************************************/ #endregion using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; namespace OSS.Tools.Http { /// /// 请求实体 /// public class OssHttpRequest { /// /// 请求构造函数 /// public OssHttpRequest() { } /// /// 请求构造函数 /// /// 请求地址 public OssHttpRequest(string reqUrl) { address_url = reqUrl; } /// /// reqMessage 设置方法 /// 如果当前的设置不能满足需求,可以通过这里再次设置 /// public Action RequestSet { get; set; } /// /// 如果此值设置,则忽略 Uri 值 /// public string address_url { get; set; } /// /// 请求方式 /// public HttpMethod http_method { get; set; } = HttpMethod.Get; #region 请求的内容参数 /// /// 是否存在文件 /// public bool has_file => _fileParameters != null && _fileParameters.Any(); private List _fileParameters; /// /// 文件参数列表 /// public IReadOnlyList FileParameters => _fileParameters ; /// /// 添加文件 /// /// public void AddFile(FileParameter file) { if (_fileParameters==null) { _fileParameters = new List(); } _fileParameters.Add(file); } private List _formParameters; /// /// 非文件参数列表 /// public IReadOnlyList FormParameters => _formParameters ;// 兼容老版本,取值时默认赋值 /// /// 添加表单参数 /// /// /// public void AddFormPara(string name, object value) { if (_formParameters == null) { _formParameters = new List(); } _formParameters.Add(new FormParameter(name,value)); } #endregion /// /// 自定义内容实体 /// eg:当上传文件时,无法自定义内容 /// public string custom_body { get; set; } /// /// 发送前准备 /// protected internal virtual void PrepareSend() { } } }