Пример #1
0
 /// <summary>
 /// 写入 Form 的内容值(非文件参数)
 /// </summary>
 /// <param name="param"></param>
 /// <param name="boundary"></param>
 /// <returns></returns>
 protected static string GetMultipartFormData(Parameter param, string boundary)
 {
     return string.Format("--{0}{3}Content-Disposition: form-data; name=\"{1}\"{3}{3}{2}{3}",
         boundary, param.Name, param.Value, _lineBreak);
 }
        protected static IHttpRequest ConfigHttpRequest(string url, Dictionary<string, object> fields, Dictionary<string, object> headers, HttpMothed method, ParameterType parameterType)
        {
            IHttpRequest request = new HttpRequest();

            request.HttpMothed = method;
            IList<Parameter> parameters = new List<Parameter>();
            if (fields != null && fields.Count > 0)
            {
                foreach (var item in fields)
                {
                    Parameter p = new Parameter();
                    p.Name = item.Key;
                    p.Value = item.Value;
                    p.Type = parameterType;
                    parameters.Add(p);
                }
            }
            request.Parameters = parameters;

            parameters = new List<Parameter>();
            if (headers != null && headers.Count > 0)
            {
                foreach (var item in headers)
                {
                    Parameter p = new Parameter();
                    p.Name = item.Key;
                    p.Value = item.Value;
                    p.Type = ParameterType.Header;
                    request.HeaderParameters.Add(p);
                }
            }

            request.AddressUrl = url;
            return request;
        }