本文整理汇总了C#中IHttpClient类的典型用法代码示例。如果您正苦于以下问题:C# IHttpClient类的具体用法?C# IHttpClient怎么用?C# IHttpClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IHttpClient类属于命名空间,在下文中一共展示了IHttpClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HomeController
public HomeController(
IHttpClient client,
IEndpointsConfiguration endpointsConfiguration)
{
_client = client;
_endpointsConfiguration = endpointsConfiguration;
}
示例2: DefaultRequestExecutor
public DefaultRequestExecutor(
IHttpClient httpClient,
IClientApiKey apiKey,
AuthenticationScheme authenticationScheme,
ILogger logger,
IBackoffStrategy defaultBackoffStrategy,
IBackoffStrategy throttlingBackoffStrategy)
{
if (!apiKey.IsValid())
{
throw new ApplicationException("API Key is invalid.");
}
this.httpClient = httpClient;
this.syncHttpClient = httpClient as ISynchronousHttpClient;
this.asyncHttpClient = httpClient as IAsynchronousHttpClient;
this.apiKey = apiKey;
this.authenticationScheme = authenticationScheme;
IRequestAuthenticatorFactory requestAuthenticatorFactory = new DefaultRequestAuthenticatorFactory();
this.requestAuthenticator = requestAuthenticatorFactory.Create(authenticationScheme);
this.logger = logger;
this.defaultBackoffStrategy = defaultBackoffStrategy;
this.throttlingBackoffStrategy = throttlingBackoffStrategy;
}
示例3: UsageReporter
public UsageReporter(IApplicationHost applicationHost, IHttpClient httpClient, IUserManager userManager, ILogger logger)
{
_applicationHost = applicationHost;
_httpClient = httpClient;
_userManager = userManager;
_logger = logger;
}
示例4: GetNegotiationResponse
// virtual to allow mocking
public virtual Task<NegotiationResponse> GetNegotiationResponse(IHttpClient httpClient, IConnection connection, string connectionData)
{
if (httpClient == null)
{
throw new ArgumentNullException("httpClient");
}
if (connection == null)
{
throw new ArgumentNullException("connection");
}
var negotiateUrl = UrlBuilder.BuildNegotiate(connection, connectionData);
httpClient.Initialize(connection);
return httpClient.Get(negotiateUrl, connection.PrepareRequest, isLongRunning: false)
.Then(response => response.ReadAsString())
.Then(raw =>
{
if (String.IsNullOrEmpty(raw))
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_ServerNegotiationFailed));
}
return JsonConvert.DeserializeObject<NegotiationResponse>(raw);
});
}
示例5: WebSocketTransport
public WebSocketTransport(IHttpClient client)
: base(client, "webSockets")
{
_disconnectToken = CancellationToken.None;
ReconnectDelay = TimeSpan.FromSeconds(2);
_webSocketHandler = new ClientWebSocketHandler(this);
}
示例6: ChannelImageProvider
public ChannelImageProvider(ILiveTvManager liveTvManager, IHttpClient httpClient, ILogger logger, IApplicationHost appHost)
{
_liveTvManager = liveTvManager;
_httpClient = httpClient;
_logger = logger;
_appHost = appHost;
}
示例7: FanArtAlbumProvider
/// <summary>
/// Initializes a new instance of the <see cref="FanArtAlbumProvider"/> class.
/// </summary>
/// <param name="httpClient">The HTTP client.</param>
/// <param name="logManager">The log manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="providerManager">The provider manager.</param>
public FanArtAlbumProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager, IFileSystem fileSystem)
: base(logManager, configurationManager)
{
_providerManager = providerManager;
_fileSystem = fileSystem;
HttpClient = httpClient;
}
示例8: MovieDbImagesProvider
/// <summary>
/// Initializes a new instance of the <see cref="MovieDbImagesProvider"/> class.
/// </summary>
/// <param name="logManager">The log manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="providerManager">The provider manager.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="httpClient">The HTTP client.</param>
public MovieDbImagesProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager, IJsonSerializer jsonSerializer, IHttpClient httpClient)
: base(logManager, configurationManager)
{
_providerManager = providerManager;
_jsonSerializer = jsonSerializer;
_httpClient = httpClient;
}
示例9: PostAsync
public static EventSignal<IResponse> PostAsync(
IHttpClient client,
string url,
Action<IRequest> prepareRequest)
{
return client.PostAsync(url, prepareRequest, null);
}
示例10: PismoInstaller
public PismoInstaller(IHttpClient httpClient, ILogger logger, IApplicationPaths appPaths, IZipClient zipClient)
{
_httpClient = httpClient;
_logger = logger;
_appPaths = appPaths;
_zipClient = zipClient;
}
示例11: GetRegistrationStatus
public static async Task<MBRegistrationRecord> GetRegistrationStatus(IHttpClient httpClient, IJsonSerializer jsonSerializer, string feature, string mb2Equivalent = null, string version = null)
{
//check the reg file first to alleviate strain on the MB admin server - must actually check in every 30 days tho
var reg = new RegRecord {registered = LicenseFile.LastChecked(feature) > DateTime.UtcNow.AddDays(-30)};
if (!reg.registered)
{
var mac = _networkManager.GetMacAddress();
var data = new Dictionary<string, string> { { "feature", feature }, { "key", SupporterKey }, { "mac", mac }, { "mb2equiv", mb2Equivalent }, { "legacykey", LegacyKey }, { "ver", version }, { "platform", Environment.OSVersion.VersionString } };
try
{
using (var json = await httpClient.Post(MBValidateUrl, data, CancellationToken.None).ConfigureAwait(false))
{
reg = jsonSerializer.DeserializeFromStream<RegRecord>(json);
}
if (reg.registered)
{
LicenseFile.AddRegCheck(feature);
}
else
{
LicenseFile.RemoveRegCheck(feature);
}
}
catch (Exception e)
{
_logger.ErrorException("Error checking registration status of {0}", e, feature);
}
}
return new MBRegistrationRecord {IsRegistered = reg.registered, ExpirationDate = reg.expDate, RegChecked = true};
}
示例12: FixtureSetup
public void FixtureSetup()
{
HttpClientMock = MockRepository.GenerateMock<IHttpClient>();
Client = new RestBroadcastClient(HttpClientMock);
var localTimeZoneRestriction = new CfLocalTimeZoneRestriction(DateTime.Now, DateTime.Now);
CfResult[] result = { CfResult.Received };
CfRetryPhoneType[] phoneTypes = { CfRetryPhoneType.FirstNumber };
var broadcastConfigRestryConfig = new CfBroadcastConfigRetryConfig(1000, 2, result, phoneTypes);
var expectedTextBroadcastConfig = new CfTextBroadcastConfig(1, DateTime.Now, "fromNumber", localTimeZoneRestriction, broadcastConfigRestryConfig, "Test", CfBigMessageStrategy.DoNotSend);
ExpectedBroadcast = new CfBroadcast(1894, "broadcast", CfBroadcastStatus.Running, DateTime.Now, CfBroadcastType.Text, expectedTextBroadcastConfig);
var response = string.Format(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
"<r:ResourceReference xmlns=\"http://api.callfire.com/data\" xmlns:r=\"http://api.callfire.com/resource\">" +
"<r:Id>{0}</r:Id>" +
"<r:Location>https://www.callfire.com/api/1.1/rest/broadcast/{0}</r:Location>" +
"</r:ResourceReference>", ExpectedBroadcast.Id);
HttpClientMock
.Stub(j => j.Send(Arg<string>.Is.Equal("/broadcast"),
Arg<HttpMethod>.Is.Equal(HttpMethod.Post),
Arg<BroadcastRequest>.Matches(x => x.Broadcast.id == ExpectedBroadcast.Id &&
x.Broadcast.Name == ExpectedBroadcast.Name &&
x.Broadcast.LastModified == ExpectedBroadcast.LastModified &&
x.Broadcast.Status == BroadcastStatus.RUNNING &&
x.Broadcast.Type == BroadcastType.TEXT)))
.Return(response);
}
示例13: DlnaEntryPoint
public DlnaEntryPoint(IServerConfigurationManager config,
ILogManager logManager,
IServerApplicationHost appHost,
INetworkManager network,
ISessionManager sessionManager,
IHttpClient httpClient,
ILibraryManager libraryManager,
IUserManager userManager,
IDlnaManager dlnaManager,
IImageProcessor imageProcessor,
IUserDataManager userDataManager,
ILocalizationManager localization,
IMediaSourceManager mediaSourceManager,
ISsdpHandler ssdpHandler)
{
_config = config;
_appHost = appHost;
_network = network;
_sessionManager = sessionManager;
_httpClient = httpClient;
_libraryManager = libraryManager;
_userManager = userManager;
_dlnaManager = dlnaManager;
_imageProcessor = imageProcessor;
_userDataManager = userDataManager;
_localization = localization;
_mediaSourceManager = mediaSourceManager;
_ssdpHandler = (SsdpHandler)ssdpHandler;
_logger = logManager.GetLogger("Dlna");
}
示例14: DataServicePackageRepository
public DataServicePackageRepository(IHttpClient client, PackageDownloader packageDownloader)
{
if (client == null)
{
throw new ArgumentNullException("client");
}
if (packageDownloader == null)
{
throw new ArgumentNullException("packageDownloader");
}
_httpClient = client;
_httpClient.AcceptCompression = true;
_packageDownloader = packageDownloader;
if (EnvironmentUtility.RunningFromCommandLine || EnvironmentUtility.IsMonoRuntime)
{
_packageDownloader.SendingRequest += OnPackageDownloaderSendingRequest;
}
else
{
// weak event pattern
SendingRequestEventManager.AddListener(_packageDownloader, this);
}
}
示例15: GetTrailerList
/// <summary>
/// Downloads a list of trailer info's from the apple url
/// </summary>
/// <returns>Task{List{TrailerInfo}}.</returns>
public static async Task<List<TrailerInfo>> GetTrailerList(IHttpClient httpClient, CancellationToken cancellationToken)
{
var stream = await httpClient.Get(new HttpRequestOptions
{
Url = TrailerFeedUrl,
CancellationToken = cancellationToken,
ResourcePool = Plugin.Instance.AppleTrailers
}).ConfigureAwait(false);
var list = new List<TrailerInfo>();
using (var reader = XmlReader.Create(stream, new XmlReaderSettings { Async = true }))
{
await reader.MoveToContentAsync().ConfigureAwait(false);
while (await reader.ReadAsync().ConfigureAwait(false))
{
cancellationToken.ThrowIfCancellationRequested();
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "movieinfo":
var trailer = FetchTrailerInfo(reader.ReadSubtree());
list.Add(trailer);
break;
}
}
}
}
return list;
}