Example #1
0
        /// <summary>
        /// 执行POST请求
        /// </summary>
        /// <typeparam name="TResponse">响应</typeparam>
        /// <typeparam name="TMODELRequest">请求模型</typeparam>
        /// <typeparam name="TModelResponse">响应模型</typeparam>
        /// <param name="request">请求参数</param>
        /// <param name="accessToken">令牌值</param>
        /// <returns>响应参数</returns>
        public async Task <TResponse> ExecuteAsync <TResponse, TMODELRequest, TModelResponse> (POSTRequest <TResponse, TMODELRequest, TModelResponse> request, string accessToken = null)
            where TResponse : POSTResponse <TModelResponse>
            where TMODELRequest : POSTRequestModel
            where TModelResponse : class
        {
            var _accessToken     = accessToken ?? AccessToken;
            Uri url              = CreatePOSTUrl(APIDoman, request.APIName, request.APIVersion, _accessToken);
            var request_json     = CreatePOSTParameter(request, APIDoman, _accessToken);
            var httpmsg_response = await HTTPClient.PostAsync(url, request_json, MediaTypeHeaderValue.Parse("application/json;charset=utf-8"));

            string response = await httpmsg_response.Content.ReadAsStringAsync();

            try {
                return(response.ToJsonObj <TResponse> ());
            } catch (Newtonsoft.Json.JsonReaderException) {
                throw new Newtonsoft.Json.JsonReaderException($"未识别的JSON字符串:{response}");
            }
        }
Example #2
0
 public HttpResponseMessage PostItem <T>(object content)
 {
     return(HTTPClient.PostAsync(GetEndPoint <T>(), Helpers.NewStringContent(content)).Result);
 }
 public void PostAsync(string url, string data, LuaFunction callback = null)
 {
     HTTPClient.PostAsync(url, data, (r, e) => callback?.Call(r ?? e?.Message ?? null)).ConfigureAwait(false);
 }