Exemple #1
0
        public void Post(string url, byte[] body, Dictionary <string, string> headers, Action <byte[]> callback)
        {
            var networkRequestData = new NetworkRequestData
            {
                url      = url,
                body     = body,
                method   = "POST",
                headers  = headers,
                callback = callback
            };

            try
            {
                var request = WebRequest.Create(url) as HttpWebRequest;
                request.Method          = "POST";
                request.CookieContainer = m_cookieContainer;
                ParseHeader(request, headers);

                if (body != null)
                {
                    request.ContentLength = body.Length;
                    Stream requestStream = request.GetRequestStream();
                    requestStream.Write(body, 0, body.Length);
                }

                request.BeginGetResponse(OnFinishWebRequest, new Tuple <HttpWebRequest, NetworkRequestData>(request, networkRequestData));
            }
            catch (Exception e)
            {
                OnRequestFailure?.Invoke(networkRequestData);
            }
        }
Exemple #2
0
        public void Get(string url, Dictionary <string, string> headers, Action <byte[]> callback)
        {
            var networkRequestData = new NetworkRequestData
            {
                url      = url,
                body     = null,
                method   = "GET",
                headers  = headers,
                callback = callback
            };

            try
            {
                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                request.Method          = "GET";
                request.CookieContainer = m_cookieContainer;
                ParseHeader(request, headers);

                request.BeginGetResponse(new AsyncCallback(OnFinishWebRequest), new Tuple <HttpWebRequest, NetworkRequestData>(request, networkRequestData));
            }
            catch (Exception e)
            {
                OnRequestFailure?.Invoke(networkRequestData);
            }
        }