本文整理汇总了C#中IWebClient类的典型用法代码示例。如果您正苦于以下问题:C# IWebClient类的具体用法?C# IWebClient怎么用?C# IWebClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IWebClient类属于命名空间,在下文中一共展示了IWebClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TwitterAccountProvider
public TwitterAccountProvider(IWebClient webClient, UserCredential userCredential)
:base(webClient)
{
if (userCredential.AccessToken == null)
{
throw new ArgumentException("TwitterAccountProvider didn't receive AccessToken");
}
if (userCredential.AccessTokenSecret == null)
{
throw new ArgumentException("TwitterAccountProvider didn't receive AccessTokenSecret");
}
if (userCredential.ConsumerKey == null)
{
throw new ArgumentException("TwitterAccountProvider didn't receive ConsumerKey");
}
if (userCredential.ConsumerSecret == null)
{
throw new ArgumentException("TwitterAccountProvider didn't receive ConsumerSecret");
}
_accessToken = userCredential.AccessToken;
_accessTokenSecret = userCredential.AccessTokenSecret;
_consumerKey = userCredential.ConsumerKey;
_consumerSecret = userCredential.ConsumerSecret;
}
示例2: WebQueueValidator
public WebQueueValidator(Uri managementUri, IWebTokenProvider tokenProvider, IWebClient webClient)
{
_managementUri = managementUri;
_webClient = webClient;
_requestFactory = new WebRequestFactory(tokenProvider);
_uriCreator = new UriCreator(managementUri);
}
示例3: TryDownloadAsync
async Task TryDownloadAsync(TransferSpec spec, IWebClient webClient, IAbsoluteFilePath tmpFile) {
try {
tmpFile.RemoveReadonlyWhenExists();
if (!string.IsNullOrWhiteSpace(spec.Uri.UserInfo))
webClient.SetAuthInfo(spec.Uri);
using (webClient.HandleCancellationToken(spec))
await webClient.DownloadFileTaskAsync(spec.Uri, tmpFile.ToString()).ConfigureAwait(false);
VerifyIfNeeded(spec, tmpFile);
_fileOps.Move(tmpFile, spec.LocalFile);
} catch (OperationCanceledException e) {
_fileOps.DeleteIfExists(tmpFile.ToString());
throw CreateTimeoutException(spec, e);
} catch (WebException ex) {
_fileOps.DeleteIfExists(tmpFile.ToString());
var cancelledEx = ex.InnerException as OperationCanceledException;
if (cancelledEx != null)
throw CreateTimeoutException(spec, cancelledEx);
if (ex.Status == WebExceptionStatus.RequestCanceled)
throw CreateTimeoutException(spec, ex);
var response = ex.Response as HttpWebResponse;
if (response == null)
throw GenerateDownloadException(spec, ex);
switch (response.StatusCode) {
case HttpStatusCode.NotFound:
throw new RequestFailedException("Received a 404: NotFound response", ex);
case HttpStatusCode.Forbidden:
throw new RequestFailedException("Received a 403: Forbidden response", ex);
case HttpStatusCode.Unauthorized:
throw new RequestFailedException("Received a 401: Unauthorized response", ex);
}
throw GenerateDownloadException(spec, ex);
}
}
示例4: Setup
public void Setup()
{
// Query to facebook api
UserInfoUrl = String.Format(@"https://graph.facebook.com/v2.0/me?access_token={0}&fields=id,first_name,last_name,name,gender,email,birthday,timezone,location,picture.type(large)",
AccessToken);
// Object that we will make Json
_fbUserData = new FacebookUserData
{
Id = "12345",
FirstName = "Beseda",
LastName = "Dmitrij",
Name = "Beseda Dmitrij",
Gender = "male",
Email = "[email protected]",
Birthday = "12/1/1992",
Timqzone = 2,
Location = new FacebookUserData.FbLocation() {Id = "1", Name = "Donetsk, Ukraine"},
Picture = new FacebookUserData.FbPicture()
{
Data = new FacebookUserData.Data
{
Url = "photo.jpg"
}
},
};
_userToJson = JsonConvert.SerializeObject(_fbUserData);
_webRequest = Substitute.For<IWebClient>();
_webRequest.GetWebData(UserInfoUrl).Returns(Task.FromResult(_userToJson));
}
示例5: RssPlugin
public RssPlugin(IBitTorrentEngine torrentEngine, IDataRepository dataRepository, ITimerFactory timerFactory, IWebClient webClient)
{
_torrentEngine = torrentEngine;
_dataRepository = dataRepository;
_timer = timerFactory.CreateTimer();
_webClient = webClient;
}
示例6: Setup
public void Setup()
{
client = Substitute.For<IWebClient>();
client.Download().Returns(downloadStringResult);
target = new WebRequestBuilder(client);
}
示例7: SetUp
public void SetUp()
{
_mockWebClient = MockRepository.GenerateStub<IWebClient>();
var uri = new Uri("http://valid");
_uri = uri.ToString();
_resolver = new HttpProjectXmlResolver(uri) { WebClient = _mockWebClient };
}
示例8: HtmlForm
/// <summary>
/// Initializes a new instance of the <see cref="HtmlForm"/> class.
/// </summary>
/// <param name="webClient">Contains the web client to be used to request and submit the form.</param>
protected HtmlForm( IWebClient webClient )
{
WebClient = webClient;
Attributes = new Dictionary<string, string>( StringComparer.OrdinalIgnoreCase );
Controls = new List<HtmlFormControl>();
}
示例9: CypherClientFactory
public CypherClientFactory(string baseUri, IWebClient webClient, IWebSerializer serializer, IEntityCache entityCache)
{
this._baseUri = baseUri;
this._webClient = webClient;
this._serializer = serializer;
this._entityCache = entityCache;
}
示例10: ApplyConstraint
public void ApplyConstraint(IWebClient client)
{
foreach (var constraint in Constraints)
{
constraint.ApplyConstraint(client);
}
}
示例11: SetUp
public void SetUp()
{
// Query to VK api
UserInfoUrl = String.Format(
@"https://api.vk.com/method/users.get?user_id={0}&fields=screen_name,bdate,sex,city,country,photo_max_orig,timezone&v=5.23&access_token={1}",
UserId,
AccessToken);
// Object that we will make Json
_vkUserData = new VkUserData.VkResponse
{
Response = new List<VkUserData>
{
new VkUserData
{
FirstName = "Beseda",
LastName = "Dmitrij",
ScreenName = "Beseda Dmitrij",
Sex = VkUserData.VkSex.Male,
Birthday = "12/1/1992",
City = new VkUserData.VkCity {Id = 1, Title = "Donetsk"},
Country = new VkUserData.VkCountry {Id = 1, Title = "Ukraine"},
Timezone = 2,
Photo = "photo.jpg",
Email = Email
}
}
};
// Make Json
_userToJson = JsonConvert.SerializeObject(_vkUserData);
_webRequest = Substitute.For<IWebClient>();
_webRequest.GetWebData(UserInfoUrl).Returns(Task.FromResult(_userToJson));
}
示例12: Setup
public void Setup()
{
client = Substitute.For<IWebClient>();
client.Headers.Returns(new WebHeaderCollection());
target = new WebServiceBuilder(client);
}
示例13: BuildDataFetcher
public BuildDataFetcher(ViewUrl viewUrl, IConfigSettings configSettings,
IWebClientFactory webClientFactory)
{
_viewUrl = viewUrl;
_webClientFactory = webClientFactory;
_webClient = webClientFactory.GetWebClient(configSettings.URL);
configSettings.AddObserver(this);
}
示例14: BurritoDayModel
public BurritoDayModel(IFiber fiber, IWebClient client)
{
this.fiber = fiber;
this.client = client;
this.fiber.ScheduleOnInterval(this.PollState, 0,
(long)this.interval.TotalMilliseconds);
}
示例15: ServiceBusClient
public ServiceBusClient(Uri address, IWebTokenProvider tokenManager, IWebClient webClient)
{
_address = address;
_tokenManager = tokenManager;
_webClient = webClient;
_webRequestFactory = new WebRequestFactory(tokenManager);
_serializer = new MessageSerializer();
}