本文整理汇总了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();
}
示例2: Establish_context
protected static void Establish_context()
{
entity = CurveData.CreateBasicEntity();
var notAMapping = new Contracts.Curve();
content = HttpContentExtensions.CreateDataContract(notAMapping);
client = new HttpClient();
}
示例3: Establish_context
protected static void Establish_context()
{
curve = CurveData.CreateContractForEntityCreation();
content = HttpContentExtensions.CreateDataContract(curve);
client = new HttpClient();
}
示例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();
}
示例5: HttpClientWrapper
public HttpClientWrapper(HttpClient httpClient, RequestHeaders requestHeaders = null)
{
_httpClient = httpClient;
if (requestHeaders != null)
_httpClient.DefaultHeaders = requestHeaders;
}
示例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);
}
}
}
}
示例7: Establish_context
protected static void Establish_context()
{
person = Script.PersonData.CreateContractForEntityCreation();
content = HttpContentExtensions.CreateDataContract(person);
client = new HttpClient();
}
示例8: Establish_context
protected static void Establish_context()
{
broker = BrokerData.CreateContractForEntityCreation();
content = HttpContentExtensions.CreateDataContract(broker);
client = new HttpClient();
}
示例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);
}
}
}
示例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");
}
}
示例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);
}
示例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;
}
}
示例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();
}
示例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();
}
示例15: Establish_context
protected static void Establish_context()
{
exchange = ExchangeData.CreateContractForEntityCreation();
content = HttpContentExtensions.CreateDataContract(exchange);
client = new HttpClient();
}