当前位置: 首页>>代码示例>>C#>>正文


C# HttpClient.GetString方法代码示例

本文整理汇总了C#中HttpClient.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.GetString方法的具体用法?C# HttpClient.GetString怎么用?C# HttpClient.GetString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpClient的用法示例。


在下文中一共展示了HttpClient.GetString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExResult

        /// <summary>
        /// 发送HTTP请求
        /// </summary>
        /// <param name="url">请求的URL</param>
        /// <param name="param">请求的参数</param>
        /// <returns>请求结果</returns>
        public string ExResult(BodyParam param = null)
        {
            param = param == null ? new BodyParam() : param;

            HttpClient httpclient = new HttpClient(url);
            httpclient.PostingData.Add("apikey", apikey);
            httpclient.PostingData.Add("fromdevice", param.fromdevice);
            httpclient.PostingData.Add("clientip", param.clientip);
            httpclient.PostingData.Add("detecttype", param.detecttype);
            httpclient.PostingData.Add("languagetype", param.languagetype);
            httpclient.PostingData.Add("imagetype", param.imagetype);
            httpclient.PostingData.Add("image", param.image);
            httpclient.RequestHeaders.Add("apikey", apikey);
            string res = httpclient.GetString();
            httpclient.Reset();
            return res;
        }
开发者ID:SpeakHero,项目名称:WeChatPlatform,代码行数:23,代码来源:BaiduORC.cs

示例2: ExclusiveMode

        public void ExclusiveMode() {
            auth.ExclusiveAuth = true;
            var h1 = new HttpClient { Cookies = new CookieCollection() };
            var h2 = new HttpClient { Cookies = new CookieCollection() };
            h1.GetString("http://127.0.0.1:14990/logon", "login=a&pass=a", r =>
            {
                r.UserAgent = "agent1";
            });
            Assert.AreEqual("true", h1.GetString("http://127.0.0.1:14990/isauth", null, r =>
            {
                r.UserAgent = "agent1";
            }));
            h2.GetString("http://127.0.0.1:14990/logon", "login=a&pass=a", r =>
            {
                r.UserAgent = "agent2";
            });

            Assert.AreEqual("true", h2.GetString("http://127.0.0.1:14990/isauth", null, r =>
            {
                r.UserAgent = "agent2";
            }));
            Assert.AreEqual("false", h1.GetString("http://127.0.0.1:14990/isauth", null, r =>
            {
                r.UserAgent = "agent1";
            }));
           

        }
开发者ID:Qorpent,项目名称:qorpent.sys,代码行数:28,代码来源:AuthenticationTests.cs


注:本文中的HttpClient.GetString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。