本文整理汇总了C#中Microsoft.Http.HttpClient.Get方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.Get方法的具体用法?C# HttpClient.Get怎么用?C# HttpClient.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Http.HttpClient
的用法示例。
在下文中一共展示了HttpClient.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
}
}
示例2: 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);
}
}
}
}
示例3: 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);
}
示例4: 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);
}
}
}
示例5: 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();
}
示例6: GetLocations
static String GetLocations(HttpClient client)
{
String locations;
HttpResponseMessage response = client.Get("Locations");
response.EnsureStatusIsSuccessful();
locations = response.Content.ReadAsString();
return locations;
}
示例7: Because_of
protected static void Because_of()
{
client = new HttpClient(ServiceUrl["Exchange"] +
"map?source-system=Trayport&mapping-string=" + exchange.Mappings[0].MappingValue + "&as-of=" +
exchange.Validity.Start.ToString(DateFormatString));
response = client.Get();
}
示例8: Because_of
protected static void Because_of()
{
var entity = CurveData.CreateBasicEntityWithOneMapping();
client = new HttpClient(ServiceUrl["Curve"] + string.Format("{0}/mapping/{1}", entity.Id, int.MaxValue));
response = client.Get();
}
示例9: UploadFile
/*
static void UploadFile(string baseAddress)
{
string uploadUri = "UploadFile/" + "jsonData.zip";
Console.WriteLine("Uplaoding location data");
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(baseAddress + uploadUri);
req.ContentType = "text/plain";
Stream reqStream = req.GetRequestStream();
HttpContent content = HttpContentExtensions.CreateDataContract<string>(data);
HttpResponseMessage response = client.Post(uploadUri, content);
response.EnsureStatusIsSuccessful();
return response.Content.ReadAsString();
}*/
static Location GetLocation(HttpClient client, int id)
{
// Getting the response as a string
Console.WriteLine("Location: {0}", id);
string getUri = "Locations/" + id.ToString();
HttpResponseMessage response = client.Get(getUri);
response.EnsureStatusIsSuccessful();
return response.Content.ReadAsJsonDataContract<Location>();
}
示例10: Establish_context
protected static void Establish_context()
{
client = new HttpClient();
entity = BrokerData.CreateBasicEntity();
var getResponse = client.Get(ServiceUrl["Broker"] + entity.Id);
updatedContract = getResponse.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Broker>();
content = HttpContentExtensions.CreateDataContract(BrokerData.MakeChangeToContract(updatedContract));
}
示例11: Establish_context
protected static void Establish_context()
{
client = new HttpClient();
entity = Script.SourceSystemData.CreateBasicEntity();
var getResponse = client.Get(ServiceUrl["SourceSystem"] + entity.Id);
updatedContract = getResponse.Content.ReadAsDataContract<EnergyTrading.Mdm.Contracts.SourceSystem>();
content = HttpContentExtensions.CreateDataContract(Script.SourceSystemData.MakeChangeToContract(updatedContract));
}
示例12: Because_of
protected static void Because_of()
{
entity = BrokerData.CreateBasicEntityWithOneMapping();
mapping = entity.Mappings[0];
client = new HttpClient(ServiceUrl["Broker"] + string.Format("{0}/mapping/{1}", entity.Id, mapping.Id));
response = client.Get();
mappingResponse = response.Content.ReadAsDataContract<EnergyTrading.Mdm.Contracts.MappingResponse>();
}
示例13: TestConnection
public string TestConnection()
{
HttpClient client = new HttpClient(URL);
client.TransportSettings.Credentials = new NetworkCredential(APIToken, "");
HttpResponseMessage msg = client.Get("account.xml");
msg.EnsureStatusIsSuccessful();
return msg.Content.ReadAsString();
}
示例14: Establish_context
protected static void Establish_context()
{
client = new HttpClient();
entity = PartyRoleData.CreateBasicEntity();
var getResponse = client.Get(ServiceUrl["PartyRole"] + entity.Id);
updatedContract = getResponse.Content.ReadAsDataContract<OpenNexus.MDM.Contracts.PartyRole>();
content = HttpContentExtensions.CreateDataContract(PartyRoleData.MakeChangeToContract(updatedContract));
}
示例15: Because_of
protected static void Because_of()
{
client = new HttpClient(ServiceUrl["Location"] +
"crossmap?source-system=" + trayport.Name + "&destination-system=" + endur.Name + "&mapping-string=" + trayportMapping.MappingValue);
response = client.Get();
mappingResponse = response.Content.ReadAsDataContract<EnergyTrading.Mdm.Contracts.Fault>();
}
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:9,代码来源:fails_with_no_default_and_multiple_mappings.cs