예제 #1
0
        /// <summary>
        /// Получение json по url-адресу
        /// </summary>
        /// <param name="url">Адрес получения json</param>
        /// <returns>Строка в формате json</returns>
        public string GetJson(string url)
        {
            var separatorPosition = url.IndexOf('?');
            var methodUrl         = separatorPosition < 0 ? url : url.Substring(0, separatorPosition);
            var parameters        = separatorPosition < 0 ? string.Empty : url.Substring(separatorPosition + 1);

            return(WebCall.MakeCall(methodUrl, _host, _port).Response);
        }
예제 #2
0
        //public static WebCallResult PostCall(string url, string parameters, string host = null, int? port = null)
        //{
        //    var call = new WebCall(url, new Cookies(), host, port);
        //    call.Request.Method = "POST";
        //    call.Request.ContentType = "application/x-www-form-urlencoded";
        //    var data = Encoding.UTF8.GetBytes(parameters);
        //    call.Request.ContentLength = data.Length;
        //    using (var requestStream = call.Request.GetRequestStream())
        //        requestStream.Write(data, 0, data.Length);
        //    return call.MakeRequest(host, port);
        //}

        //public static WebCallResult Post(WebForm form, string host = null, int? port = null)
        //{
        //    var call = new WebCall(form.ActionUrl, form.Cookies, host, port);
        //    var request = call.Request;
        //    request.Method = "POST";
        //    request.ContentType = "application/x-www-form-urlencoded";
        //    var formRequest = form.GetRequest();
        //    request.ContentLength = formRequest.Length;
        //    request.Referer = form.OriginalUrl;
        //    request.GetRequestStream().Write(formRequest, 0, formRequest.Length);
        //    request.AllowAutoRedirect = false;
        //    return call.MakeRequest(host, port);
        //}

        private WebCallResult RedirectTo(string url, string host = null, int?port = null)
        {
            var call = new WebCall(url, Result.Cookies, host, port);

            var request = call.Request;

            request.Method      = "GET";
            request.ContentType = "text/html";
            request.Referer     = Request.Referer;

            return(call.MakeRequest(host, port));
        }
예제 #3
0
        public static WebCallResult MakeCall(string url, string host = null, int?port = null)
        {
            var call = new WebCall(url, new Cookies(), host, port);

            return(call.MakeRequest(host, port));
        }