本文整理汇总了C#中HttpClient.Get方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.Get方法的具体用法?C# HttpClient.Get怎么用?C# HttpClient.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: backgroundWorker1_DoWork
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
switch (e.Argument.ToString())
{
case "GetServerTime":
{
HttpClient client = new HttpClient();
client.Port = 80;
client.Host = "localhost";
client.Connect();
try
{
string result = client.Get("http://localhost/gettime");
Invoke(new MethodInvoker(delegate
{
MessageBox.Show(string.Format("Server time is {0}", result));
}));
}
finally
{
client.Disconnect();
}
}
break;
case "GetFile":
{
HttpClient client = new HttpClient();
client.Port = 80;
client.Host = "localhost";
client.Connect();
try
{
MemoryStream mem = new MemoryStream();
client.Get("http://localhost/getfile?name=" + textBox1.Text, mem);
if (client.Response.ResponseCode == 200)
{
Invoke(new MethodInvoker(delegate
{
Activate();
saveFileDialog.Title = string.Format("Select a target file for requested file {0}", textBox1.Text);
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
File.WriteAllBytes(saveFileDialog.FileName, mem.ToArray());
}
}));
}
else throw new Exception("Failed to get file. Code:" + client.Response.ResponseCode.ToString());
}
finally
{
client.Disconnect();
}
}
break;
}
}
示例2: ShouldReturnUnauthorizedWhenCredentialsNotProvided
public void ShouldReturnUnauthorizedWhenCredentialsNotProvided()
{
var client = new HttpClient("http://localhost:8090");
var response = client.Get("hello");
Assert.AreEqual(HttpStatusCode.Unauthorized, response.StatusCode);
}
示例3: GetMyIp
protected override string GetMyIp()
{
HttpClient client = new HttpClient(Encoding.UTF8);
string page = client.Get("http://proxyjudge.info/");
Match match = Regex.Match(page, "REMOTE_ADDR = (.*?)\\n");
if (!match.Success)
throw new GetMyIpException();
else
return match.Groups[1].Value;
}
示例4: GetAllEvents
public string GetAllEvents()
{
var client = new HttpClient();
client.DefaultHeaders.Authorization = new Credential("ArbitraryAuthHeader");
client.DefaultHeaders.Date = DateTime.Now;
client.DefaultHeaders.Accept.Add("application/xml");
var response = client.Get("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=feed122b7c1eed8ad03b49a2e27ab867&photoset_id=72157630635240178&format=rest");
return response.Content.ReadAsString();
}
示例5: GetConfiguration
public Configuration GetConfiguration()
{
var path = Path.GetFullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Replace(@"file:///", "")));
var pluginFiles = Directory.GetFiles(path, "*.dll");
var ipi = (
from file in pluginFiles
let asm = Assembly.LoadFile(file)
from type in asm.GetExportedTypes()
where typeof(IPhrInput).IsAssignableFrom(type) && type != typeof(IPhrInput)
select Activator.CreateInstance(type)
).ToArray();
List<DataUnit> knownUnits = new List<DataUnit>();
foreach (var type in this.types)
{
HttpClient Client = new HttpClient(api_endpoint);
var rawRepoData = JsonConvert.DeserializeObject<List<CarreInstance>>(Client.Get(new HttpRequestData(string.Format("instances?type={0}", type))).Data);
var subjects = rawRepoData.Select(p => p.subject).Where(p=>!knownUnits.Select(ku=>ku.OntologicName).Contains(p)).ToList().Distinct();
foreach (var subject in subjects)
{
string name = rawRepoData.Where(e => (e.predicate == "http://carre.kmi.open.ac.uk/ontology/risk.owl#observable_name" && e.subject == subject)).Select(e => e.obj).FirstOrDefault();
string identifier = rawRepoData.Where(e => (e.predicate == "http://carre.kmi.open.ac.uk/ontology/risk.owl#has_risk_element_identifier" && e.subject == subject)).Select(e => e.obj).FirstOrDefault();
if (knownUnits.Where(e=>e.OntologicClass == type).Select(e => e.Identifier).Contains(identifier))
{
identifier = string.Format("{0}#duplicated#{1}#", identifier, Guid.NewGuid().ToString());
}
if (name == null && identifier == null) // it can't be helped. Skip.
{
continue;
}
if (name == null) name = subject;
if (identifier == null) identifier = subject;
knownUnits.Add(
new DataUnit()
{
Name = name,
OntologicName = subject,
OntologicClass = type,
Identifier = identifier
}
);
}
}
return new Configuration()
{
Sources = ipi.Select(i => (IPhrInput)i).Where(i=>i.Source.SourceName == "Vivaport.eu" || i.Source.SourceName == "Microsoft HealthVault").Select(i => i.Source).ToList(),
DesiredData = knownUnits
};
}
示例6: ChangeEmailTest
public void ChangeEmailTest()
{
_changeEmailRequestUrl =
string.Format("{0}/{1}/ChangeEmail/0?session={2}&[email protected]", BaseUrl, LoginServiceUrl,
SessionId);
try
{
var client = new HttpClient(_changeEmailRequestUrl, ContentType.Xml);
Assert.IsNotNull(client, "Client Initialization Failed");
var response = client.Get<ChangeEmailResponse>();
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
示例7: ResolveAirportTest
public void ResolveAirportTest()
{
_resolveAirportRequestUrl =
string.Format("{0}/get/DestinationService.svc/resolveairport?session={1}&term={2}", BaseUrl,
SessionId, "PNQ");
try
{
var client = new HttpClient(_resolveAirportRequestUrl, ContentType.Xml);
Assert.IsNotNull(client, "Client Initialization Failed");
var response = client.Get<Airport>();
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
示例8: GetSalesSummaryTest
public void GetSalesSummaryTest()
{
_getSalesSummaryRequestUrl =
string.Format("{0}/get/AirlinesAdminService.svc/getsalessummary/PNQ/DEL/1/01-31-2013?sessionId={1}", BaseUrl,
SessionId);
try
{
var client = new HttpClient(_getSalesSummaryRequestUrl, ContentType.Xml);
Assert.IsNotNull(client, "Client Initialization Failed");
var response = client.Get<SalesSummaryResponse>();
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
示例9: ChangeMobileTest
public void ChangeMobileTest()
{
_changeMobileRequestUrl =
string.Format("{0}/{1}/changemobile/0?session={2}&mobile=1111111111", BaseUrl, LoginServiceUrl,
SessionId);
try
{
var client = new HttpClient(_changeMobileRequestUrl, ContentType.Xml);
Assert.IsNotNull(client, "Client Initialization Failed");
var response = client.Get<ChangeMobileResponse>();
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
示例10: BeginSearchTest
public void BeginSearchTest()
{
_beginSearchRequestUrl =
string.Format("{0}/{1}/beginsearch/1?session={2}", BaseUrl, SessionServiceUrl,
SessionId);
try
{
var client = new HttpClient(_beginSearchRequestUrl, ContentType.Xml);
Assert.IsNotNull(client, "Client Initialization Failed");
var response = client.Get<SearchResponse>();
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
示例11: IsProxyAnonymous
public override bool IsProxyAnonymous(Proxy proxy)
{
HttpClient client = new HttpClient(proxy, Encoding.UTF8)
{
NumberOfAttempts = NumberOfAttempts
};
string page = null;
try
{
page = client.Get("http://proxyjudge.info/");
}
catch (WebException)
{
proxy.IsOnline = false;
}
if (page == null)
return false;
if (page.Contains("<title>Proxyjudge.info</title>") && !page.Contains(MyIp))
return true;
return false;
}
示例12: VerifyMobileTest
public void VerifyMobileTest()
{
_verifyMobileRequestUrl =
string.Format("{0}/{1}/verifymobile?session={2}&authenticationId=1&mobileCode=1", BaseUrl, LoginServiceUrl,
SessionId);
try
{
var client = new HttpClient(_verifyMobileRequestUrl, ContentType.Xml);
Assert.IsNotNull(client, "Client Initialization Failed");
var response = client.Get<bool>();
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
示例13: ResetPasswordTest
public void ResetPasswordTest()
{
_resetPasswordRequestUrl =
string.Format("{0}/{1}/resetpassword/?session={2}&[email protected]&emailCode=1&newPwd=123", BaseUrl, LoginServiceUrl,
SessionId);
try
{
var client = new HttpClient(_resetPasswordRequestUrl, ContentType.Xml);
Assert.IsNotNull(client, "Client Initialization Failed");
var response = client.Get<bool>();
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
示例14: ResendEmailVerificationTest
public void ResendEmailVerificationTest()
{
_resendEmailVerificationRequestUrl =
string.Format("{0}/{1}/resendemailverification?session={2}&authenticationId=1", BaseUrl, LoginServiceUrl,
SessionId);
try
{
var client = new HttpClient(_resendEmailVerificationRequestUrl, ContentType.Xml);
Assert.IsNotNull(client, "Client Initialization Failed");
var response = client.Get<ResendEmailCodeResponse>();
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
示例15: RegisterTest
public void RegisterTest()
{
_registerRequestUrl =
string.Format("{0}/{1}/register?session={2}&[email protected]&firstName=ABC&lastName=XYZ&mobile=1111111111&captchaChallenge=Test&captchaResponse=Test", BaseUrl, LoginServiceUrl,
SessionId);
try
{
var client = new HttpClient(_registerRequestUrl, ContentType.Xml);
Assert.IsNotNull(client, "Client Initialization Failed");
var response = client.Get<RegisterResponse>();
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}