當前位置: 首頁>>代碼示例>>C#>>正文


C# Http.HttpClient類代碼示例

本文整理匯總了C#中Microsoft.Http.HttpClient的典型用法代碼示例。如果您正苦於以下問題:C# HttpClient類的具體用法?C# HttpClient怎麽用?C# HttpClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpClient類屬於Microsoft.Http命名空間,在下文中一共展示了HttpClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的Microsoft.Http.HttpClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。