public HttpRequestAsyncState(HttpWebRequest request, string urlEncodedContent, HttpResponseHandler handler)
 {
     Request           = request;
     UrlEncodedContent = urlEncodedContent;
     Handler           = handler;
 }
Exemple #2
0
        public void StartRequest(string api, string method, XHttpRequestParamters paramter, HttpResponseHandler handler, bool needAuthtication = false)
        {
            var request = (HttpWebRequest)WebRequest.Create(api);

            request.Method      = method;
            request.Accept      = "application/json";
            request.ContentType = "application/x-www-form-urlencoded";
            if (needAuthtication)
            {
                AddAuthenticationHead(new Uri(api), method, paramter);
            }
            foreach (var headerString in paramter.HeaderStrings)
            {
                request.Headers[headerString.Key] = headerString.Value;
            }
            if (paramter.BodyParamters != null)
            {
                var urlEncodedContent = paramter.BodyParamters is string?paramter.BodyParamters.ToString()
                                            : new FormUrlEncodedContent(paramter.BodyParamters.ToKeyValue()).ReadAsStringAsync().Result;

                request.BeginGetRequestStream(PostCallBack, new HttpRequestAsyncState(request, urlEncodedContent, handler));
            }
            else
            {
                request.BeginGetResponse(ReadCallBack, new HttpResponseAsyncResult(request, handler));
            }
        }
 public HttpResponseAsyncResult(HttpWebRequest request, HttpResponseHandler handler)
 {
     Request = request;
     Handler = handler;
 }