本文整理汇总了C#中HttpClient.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.GetString方法的具体用法?C# HttpClient.GetString怎么用?C# HttpClient.GetString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient.GetString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExResult
/// <summary>
/// 发送HTTP请求
/// </summary>
/// <param name="url">请求的URL</param>
/// <param name="param">请求的参数</param>
/// <returns>请求结果</returns>
public string ExResult(BodyParam param = null)
{
param = param == null ? new BodyParam() : param;
HttpClient httpclient = new HttpClient(url);
httpclient.PostingData.Add("apikey", apikey);
httpclient.PostingData.Add("fromdevice", param.fromdevice);
httpclient.PostingData.Add("clientip", param.clientip);
httpclient.PostingData.Add("detecttype", param.detecttype);
httpclient.PostingData.Add("languagetype", param.languagetype);
httpclient.PostingData.Add("imagetype", param.imagetype);
httpclient.PostingData.Add("image", param.image);
httpclient.RequestHeaders.Add("apikey", apikey);
string res = httpclient.GetString();
httpclient.Reset();
return res;
}
示例2: ExclusiveMode
public void ExclusiveMode() {
auth.ExclusiveAuth = true;
var h1 = new HttpClient { Cookies = new CookieCollection() };
var h2 = new HttpClient { Cookies = new CookieCollection() };
h1.GetString("http://127.0.0.1:14990/logon", "login=a&pass=a", r =>
{
r.UserAgent = "agent1";
});
Assert.AreEqual("true", h1.GetString("http://127.0.0.1:14990/isauth", null, r =>
{
r.UserAgent = "agent1";
}));
h2.GetString("http://127.0.0.1:14990/logon", "login=a&pass=a", r =>
{
r.UserAgent = "agent2";
});
Assert.AreEqual("true", h2.GetString("http://127.0.0.1:14990/isauth", null, r =>
{
r.UserAgent = "agent2";
}));
Assert.AreEqual("false", h1.GetString("http://127.0.0.1:14990/isauth", null, r =>
{
r.UserAgent = "agent1";
}));
}