• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Http.HttpClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.Http.HttpClient的典型用法代码示例。如果您正苦于以下问题:C# HttpClient类的具体用法?C# HttpClient怎么用?C# HttpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HttpClient类属于Microsoft.Http命名空间,在下文中一共展示了HttpClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Establish_context

        protected static void Establish_context()
        {
            sourcesystem = Script.SourceSystemData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(sourcesystem);
            client = new HttpClient();
        }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:7,代码来源:successful.cs


示例2: Establish_context

 protected static void Establish_context()
 {
     entity = CurveData.CreateBasicEntity();
     var notAMapping = new Contracts.Curve();
     content = HttpContentExtensions.CreateDataContract(notAMapping);
     client = new HttpClient();
 }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:7,代码来源:xml_data_invalid.cs


示例3: Establish_context

        protected static void Establish_context()
        {
            curve = CurveData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(curve);
            client = new HttpClient();
        }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:7,代码来源:successful.cs


示例4: Establish_context

 protected static void Establish_context()
 {
     entity = PartyRoleData.CreateBasicEntity();
     var notAMapping = new OpenNexus.MDM.Contracts.PartyRole();
     content = HttpContentExtensions.CreateDataContract(notAMapping);
     client = new HttpClient();
 }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:7,代码来源:xml_data_invalid.cs


示例5: HttpClientWrapper

        public HttpClientWrapper(HttpClient httpClient, RequestHeaders requestHeaders = null)
        {
            _httpClient = httpClient;

            if (requestHeaders != null)
                _httpClient.DefaultHeaders = requestHeaders;
        }
开发者ID:sharpshooting,项目名称:restfulie-csharp,代码行数:7,代码来源:HttpClientWrapper.cs


示例6: GetMetrics

        /// <summary>
        /// Get the results for the process monitor
        /// </summary>
        /// <param name="apiKey"></param>
        /// <param name="client"></param>
        public override void GetMetrics(string apiKey, HttpClient client)
        {
            base.GetMetrics(apiKey, client);

            using (HttpResponseMessage response = client.Get("api?action=topProcessByCPUUsage&limit=50&apikey=" + apiKey + "&output=xml&detailedResults=true"))
            {
                response.EnsureStatusIsSuccessful();

                String data = response.Content.ReadAsString();
                XDocument xml = XDocument.Parse(data);

                IEnumerable<XElement> allMetrics = null;
                foreach (MonitorDefinition sm in monitorsDefinitions)
                {
                    // Query the xml data to retrieve each test result matching the ID of the current monitor
                    allMetrics = from metricNode in xml.Descendants("test")
                                 where (string)metricNode.Element("id") == this.Id
                                 select metricNode;

                    // Enumerate the metrics and store them in their own Metric object
                    foreach (XElement xe in allMetrics)
                        foreach (string s in sm.Names)
                            if (xe.Element(s) != null)
                            {
                                Metric m = new Metric(this);
                                m.Name = s;
                                m.Result = xe.Element(s).Value;
                                m.Suffix = sm.Suffixes[sm.Names.IndexOf(s)];
                                this.AddMetric(m);
                            }
                }
            }
        }
开发者ID:flin-aa,项目名称:Windows-Monitoring-Scripts,代码行数:38,代码来源:ProcessMonitor.cs


示例7: Establish_context

        protected static void Establish_context()
        {
            person = Script.PersonData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(person);
            client = new HttpClient();
        }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:7,代码来源:successful.cs


示例8: Establish_context

        protected static void Establish_context()
        {
            broker = BrokerData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(broker);
            client = new HttpClient();
        }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:7,代码来源:successful.cs


示例9: LoginUser_Authenticate

        /// <summary>
        /// Example of calling Security.svc/getsites to display a list of sites for the 
        /// specified enterprise GUID.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void LoginUser_Authenticate(object sender, EventArgs e)
        {
            Credentials.Visible = false;
            SiteSelector.Visible = true;

            Session.Add("Password", PasswordBox.Text);
            Session.Add("Username", UserNameBox.Text);
            Session.Add("EnterpriseGUID", EnterpriseBox.Text);

            string baseurl = WebConfigurationManager.AppSettings["ETOSoftwareWS_BaseUrl"];

            using (HttpClient client = new HttpClient(baseurl))
            {
                HttpResponseMessage resp = client.Get("Security.svc/getsites/" + EnterpriseBox.Text);
                resp.EnsureStatusIsSuccessful();

                DataContractJsonSerializer siteSer = new DataContractJsonSerializer(typeof(Entry[]));
                Entry[] sites = (Entry[])siteSer.ReadObject(resp.Content.ReadAsStream());

                foreach (Entry site in sites)
                {
                    Label label = new Label();
                    label.Text = "<a href=\"Workbench.aspx?site=" + site.Key.ToString() + "\">" + site.Value + "</a></br>";
                    Panel1.Controls.Add(label);
                }
            }
        }
开发者ID:SocialSolutions,项目名称:CodeSamples,代码行数:33,代码来源:Default.aspx.cs


示例10: Logon

        /// <summary>
        /// Example of calling the Security.svc/login method to log into ETO.
        /// </summary>
        /// <param name="siteId"></param>
        protected void Logon(string siteId)
        {
            string userName = Session["Username"].ToString();
            string password = Session["Password"].ToString();
            string enterprise = Session["EnterpriseGUID"].ToString();
            string baseurl = WebConfigurationManager.AppSettings["ETOSoftwareWS_BaseUrl"];

            try
            {
                HttpClient client = new HttpClient(baseurl);
                //below is incorrect
                string json = string.Format("{{\"security\":{{\"Email\":\"{0}\",\"Password\":\"{1}\"}}}}", userName, password);

                HttpContent content = HttpContent.Create(json,"application/json");
                HttpResponseMessage resp = client.Post("Security.svc/SSOAuthenticate/", content);
                resp.EnsureStatusIsSuccessful();

                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(SSOAuthenticateResponseObject));
                SSOAuthenticateResponseObject SSOAuthenticationResponse = serializer.ReadObject(resp.Content.ReadAsStream()) as SSOAuthenticateResponseObject;
                Session["AuthToken"] = SSOAuthenticationResponse.SSOAuthenticateResult.SSOAuthToken;
            }
            catch (Exception ex)
            {
                Response.Redirect("Default.aspx");
            }
        }
开发者ID:SocialSolutions,项目名称:CodeSamples,代码行数:30,代码来源:Workbench.aspx.cs


示例11: CreateRequestsFast

        public void CreateRequestsFast() {
            

            bool stop = false;
            var sw = new Stopwatch();

            int count = 1;
            sw.Start();
            while (!stop) {
                try {
                    Uri url = new Uri("http://tmserver:8700/shopclient");
                    HttpClient hc = new HttpClient();
                    hc.TransportSettings.Credentials = new NetworkCredential("darrel", "olecom");
                    hc.TransportSettings.ConnectionTimeout = TimeSpan.FromMilliseconds(2500);
                    HttpResponseMessage resp = hc.Get(url);
                    string result = resp.Content.ReadAsString();
                }
                catch  {
                    stop = true;
                }
                count++;
                if (count == 100) stop = true;
            }

            sw.Stop();
            var speed = 100.00 / (sw.ElapsedMilliseconds/1000.00);
            Debug.WriteLine("That took " + speed);
        }
开发者ID:darrelmiller,项目名称:RESTAgent.Samples,代码行数:28,代码来源:ServiceTests.cs


示例12: Add

        public void Add(Nut nut)
        {
            Nut response = null;

            string uri = string.Format("{0}/{1}/{2}", Address.AbsoluteUri.ToLower(), Account.ToLower(), nut.Table.ToLower());

            var client = new HttpClient(uri);

            MemoryStream ms = new MemoryStream();

            DataContractSerializer s = new DataContractSerializer(typeof(Nut));
            s.WriteObject(ms, nut);

            ms.Position = 0;
            HttpResponseMessage r = client.Post(uri, HttpContent.Create(ms.ToArray(), "application/xml"));

            ms.Close();

            r.EnsureStatusIsSuccessful();

            if (r.StatusCode == System.Net.HttpStatusCode.OK)
            {
                nut.Uri = uri;

            }
        }
开发者ID:zachbonham,项目名称:squirrel,代码行数:26,代码来源:SquirrelClient.cs


示例13: Because_of

        protected static void Because_of()
        {
            client = new HttpClient(ServiceUrl["Counterparty"] +
                "crossmap?source-system=trayport&destination-system=endur&mapping-string=abc");

            response = client.Get();
        }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:7,代码来源:source_system_mapping_unkown.cs


示例14: Establish_context

 protected static void Establish_context()
 {
     entity = Script.SourceSystemData.CreateBasicEntity();
     var notAMapping = new EnergyTrading.Mdm.Contracts.SourceSystem();
     content = HttpContentExtensions.CreateDataContract(notAMapping);
     client = new HttpClient();
 }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:7,代码来源:xml_data_invalid.cs


示例15: Establish_context

        protected static void Establish_context()
        {
            exchange = ExchangeData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(exchange);
            client = new HttpClient();
        }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:7,代码来源:successful.cs


示例16: Establish_context

        protected static void Establish_context()
        {
            legalentity = LegalEntityData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(legalentity);
            client = new HttpClient();
        }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:7,代码来源:successful.cs


示例17: RESTService

        public RESTService(TestConfiguration config)
        {
            _testConfig = config;

            ServiceURI = _testConfig.ServiceURI;
            //ServicePort = TestConfig.ServicePort;

            AuthRequired = _testConfig.AuthRequired;
            AuthType = (AuthSchema)_testConfig.AuthType;
            Username = _testConfig.Username;
            Password = _testConfig.Password;
            AuthToken = _testConfig.AuthToken;
            IsConfigured = true;
            //IsOnline = true;

            // Now that the service is configured, create an http client that can talk to it...
            _client = new HttpClient();
            
            // Is auth required?
            if (AuthRequired)
            {
                if (AuthType == AuthSchema.Basic)
                    _client.TransportSettings.Credentials = new NetworkCredential(Username, Password);
                else if (AuthType == AuthSchema.Token)
                    _client.DefaultHeaders.Authorization = new Credential(AuthToken);
            }
        }
开发者ID:BorisMomtchev,项目名称:NiCris.Dashboard-.NET-4.5,代码行数:27,代码来源:RESTService.cs


示例18: Establish_context

 protected static void Establish_context()
 {
     entity = BrokerData.CreateBasicEntity();
     var notAMapping = new EnergyTrading.MDM.Contracts.Sample.Broker();
     content = HttpContentExtensions.CreateDataContract(notAMapping);
     client = new HttpClient();
 }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:7,代码来源:xml_data_invalid.cs


示例19: GetMetrics

        public override void GetMetrics(string apiKey, HttpClient client)
        {
            // Get the 'base' name of the monitor to make sure we requesting the correct monitor results. (drive_C becomes: drive)
            string baseMonitorName = Util.BaseMonitorName(this.Name, '_');

            // Post the requests
            using (HttpResponseMessage response = client.Get("api?action=top" + baseMonitorName + "&apikey=" + apiKey + "&output=xml&detailedResults=true"))
            {
                response.EnsureStatusIsSuccessful();

                String data = response.Content.ReadAsString();
                XDocument xml = XDocument.Parse(data);

                IEnumerable<XElement> allMetrics = null;
                foreach (MonitorDefinition sm in monitorsDefinitions)
                {
                    allMetrics = from metricNode in xml.Descendants("test")
                                 where (string)metricNode.Element("id") == this.Id
                                 select metricNode;

                    foreach (XElement xe in allMetrics)
                        foreach (string s in sm.Names)
                            if (xe.Element(s) != null)
                            {
                                Metric m = new Metric(this);
                                m.Name = s;
                                m.Result = xe.Element(s).Value;
                                m.Suffix = sm.Suffixes[sm.Names.IndexOf(s)];
                                this.AddMetric(m);
                            }
                }
            }
        }
开发者ID:flin-aa,项目名称:Windows-Monitoring-Scripts,代码行数:33,代码来源:GlobalMonitor.cs


示例20: Establish_context

        protected static void Establish_context()
        {
            counterparty = CounterpartyData.CreateContractForEntityCreation();

            content = HttpContentExtensions.CreateDataContract(counterparty);
            client = new HttpClient();
        }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:7,代码来源:successful.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Http.HttpContent类代码示例发布时间:2022-05-26
下一篇:
C# Canvas.CanvasDrawingSession类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap