本文整理汇总了TypeScript中typed-rest-client/HttpClient.HttpClient类的典型用法代码示例。如果您正苦于以下问题:TypeScript HttpClient类的具体用法?TypeScript HttpClient怎么用?TypeScript HttpClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpClient类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: resolve
var promise = new Promise<Release>((resolve, reject) => {
let httpClient: httpc.HttpClient = new httpc.HttpClient(userAgent, [handler]);
let taggedReleaseUrl = "https://api.github.com/repos/" + repositoryName + "/releases/tags/" + tag;
taggedReleaseUrl = taggedReleaseUrl.replace(/([^:]\/)\/+/g, "$1");
httpClient.get(taggedReleaseUrl).then((res) => {
res.readBody().then((body) => {
let response = JSON.parse(body);
let release: Release = {
Id: response["id"],
Name: response["tag_name"]
}
resolve(release);
});
}, (reason) => {
reject(reason);
});
});
示例2: isEndpointInternal
// make a request to the endpoint uri, and take a look at the response header to
// determine whether this is our service, or an external service.
private static async isEndpointInternal(endpointUri: string): Promise<boolean> {
let requestOptions: IRequestOptions;
try {
const proxy = tl.getHttpProxyConfiguration();
requestOptions = proxy ? { proxy } : {};
} catch (error) {
tl.debug('unable to determine proxy configuration: ' + error);
requestOptions = {};
}
const headers: IHeaders = {};
headers['X-TFS-FedAuthRedirect'] = 'Suppress';
const endpointClient = new HttpClient(tl.getVariable('AZURE_HTTP_USER_AGENT'), null, requestOptions);
try {
const resp = await endpointClient.get(endpointUri, headers);
return resp.message.rawHeaders !== null && resp.message.rawHeaders.some( t => t.toLowerCase().indexOf('x-tfs') >= 0 || t.toLowerCase().indexOf('x-vss') >= 0 );
} catch (error) {
tl.debug(error);
return false;
}
}