Beispiel #1
0
        public static object HttpGet(string url, object query, object headers, object authentication, object timeout, object allowRedirects)
        {
            if (ExcelDnaUtil.IsInFunctionWizard())
            {
                return("");
            }
            try
            {
                url = Schema.Trim(url);

                var httpHeaders = headers is ExcelMissing ?
                                  new Dictionary <string, string>() :
                                  ExcelParams.AsDictionary <string>(headers as object[, ]);

                if (!(authentication is ExcelMissing))
                {
                    var encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(authentication.ToString()));
                    httpHeaders["Authorization"] = "Basic " + encoded;
                }



                if (!cache.ContainsKey(url))
                {
                    cache.Set(url, httpProvider.Get(url, httpHeaders));
                }
                return(url);
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
        public void Can_Get_Http()
        {
            var url          = "http://ip.jsontest.com/";
            var httpProvider = new HttpProvider();
            var result       = httpProvider.Get(url, new Dictionary <string, string>());

            Assert.AreEqual(200, result.Value <int>("StatusCode"));
        }
        public void Can_Get_Https()
        {
            var url          = "https://jsonplaceholder.typicode.com/comments";
            var httpProvider = new HttpProvider();
            var result       = httpProvider.Get(url, new Dictionary <string, string>());

            Assert.AreEqual(200, result.Value <int>("StatusCode"));
        }
Beispiel #4
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            txtResponse.Clear();
            txtResponse.AppendText("ucHeader:" + ucHeader.GetJson());
            txtResponse.AppendText(Environment.NewLine + "ucHeader:" + ucHeader.GetPraram());
            txtResponse.AppendText(Environment.NewLine + "ucTab2FormData:" + ucTab2FormData.GetJson());
            txtResponse.AppendText(Environment.NewLine + "ucTab2FormData:" + ucTab2FormData.GetPraram());
            txtResponse.AppendText(Environment.NewLine + "ucTab2UrlEncoded:" + ucTab2UrlEncoded.GetJson());
            txtResponse.AppendText(Environment.NewLine + "ucTab2UrlEncoded:" + ucTab2UrlEncoded.GetPraram());
            txtResponse.AppendText(Environment.NewLine);


            var url = txtUrl.Text;

            if (string.IsNullOrEmpty(url))
            {
                return;
            }

            WebResponseParameter response     = null;
            IHttpProvider        httpProvider = new HttpProvider();

            var method = HttpMethod.GET;

            Enum.TryParse(cmbMethod.Text, out method);

            if (method.Equals(HttpMethod.GET))
            {
                response = httpProvider.Get(txtUrl.Text);
            }
            else if (method.Equals(HttpMethod.POST))
            {
                var tab2Selected = tabControl2.SelectedTab.Name.ToLower();
                if (tab2Selected.Equals("tab2_form_data"))
                {
                    var kvp = ucTab2FormData.GetValues();
                    response = httpProvider.Post(txtUrl.Text, kvp);
                }
                else if (tab2Selected.Equals("tab2_x_www_form_urlencoded"))
                {
                    var kvp = ucTab2UrlEncoded.GetValues();
                    response = httpProvider.Post(txtUrl.Text, kvp);
                }
                else if (tab2Selected.Equals("tab2_raw"))
                {
                    var rawType = cmbRaw.Text.ToLower();
                    if (rawType.Equals("Text".ToLower()))
                    {
                    }
                    else if (rawType.Equals("Text(text/plain)".ToLower()))
                    {
                    }
                    else if (rawType.Equals("JSON(application/json)".ToLower()))
                    {
                        var json = txtRaw.Text;
                        if (!string.IsNullOrEmpty(json))
                        {
                            response = httpProvider.Post(txtUrl.Text, json);
                        }
                    }
                    else if (rawType.Equals("Javascript(application/javascript)".ToLower()))
                    {
                    }
                    else if (rawType.Equals("XML(text/xml)".ToLower()))
                    {
                    }
                    else if (rawType.Equals("HTML(text/html)".ToLower()))
                    {
                    }
                }
                else if (tab2Selected.Equals("tab2_binary"))
                {
                }
            }



            //switch (method)
            //{
            //    case HttpMethod.GET:
            //        response = httpProvider.Get(txtUrl.Text);
            //        break;
            //    case HttpMethod.POST:
            //        response = httpProvider.Post(txtUrl.Text,para);
            //        break;
            //    case HttpMethod.PUT:
            //        break;
            //    case HttpMethod.DELETE:
            //        break;
            //    case HttpMethod.HEAD:
            //        break;
            //    case HttpMethod.CONNECT:
            //        break;
            //    case HttpMethod.OPTIONS:
            //        break;
            //    case HttpMethod.TRACE:
            //        break;
            //    default:
            //        break;
            //}

            txtResponse.AppendText(response.Body);
        }