/// <summary> /// post一个Api请求 /// </summary> /// <typeparam name="TRes"></typeparam> /// <param name="apiRoute"></param> /// <param name="req"></param> /// <param name="mothed">请求方式</param> /// <returns></returns> public static async Task <TRes> RestSnsApi <TRes>(string apiRoute, object req = null, HttpMothed mothed = HttpMothed.POST) where TRes : ResultMo, new() { var apiUrl = string.Concat(snsApiUrlPre, apiRoute); return(await RestApi <TRes>(apiUrl, req, mothed)); }
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; }
public static async Task <TRes> RestApi <TRes>(string absoluateApiUrl, object reqContent, HttpMothed mothed) where TRes : ResultMo, new() { var httpReq = new OsHttpRequest { HttpMothed = mothed, AddressUrl = absoluateApiUrl, CustomBody = reqContent == null ? null : JsonConvert.SerializeObject(reqContent, Formatting.None, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore }), RequestSet = r => { var ticket = MemberShiper.AppAuthorize.ToSignData(secretKey); r.Headers.Add(GlobalKeysUtil.AuthorizeTicketName, ticket); r.Headers.Add("Accept", "application/json"); if (r.Content != null) { r.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json") { CharSet = "UTF-8" }; } } }; return(await httpReq.RestCommonJson <TRes>()); }