# @ewsjs/xhr 中文文档

规范地址：https://npmcn.com/package/%40ewsjs/xhr/

版本：3\.1\.3
npm 元数据更新时间：2024-05-13T03:36:07.154Z
中文译文更新时间：2026-11-14T02:56:18.433Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40ewsjs/xhr
原文对照：https://npmcn.com/package/%40ewsjs/xhr/?lang=original
项目主页：https://github.com/ewsjs/xhr
源码仓库：https://github.com/ewsjs/xhr

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：46.7 kB，24 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：4 个
- 首次发布：2018-05-01T19:39:44.995Z
- 最新版本发布：2024-05-13T03:36:06.959Z
- 近 30 天下载量：241591（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：17（近 12 个月 0 个）

## 中文简介

用于ewsjs的其他 XHR 方法

## 安装

```sh
npm install @ewsjs/xhr
```

也可以使用：`pnpm add @ewsjs/xhr`、`yarn add @ewsjs/xhr`、`bun add @ewsjs/xhr`

## README

# @ewsjs/xhr (英语)

将 ews- javascript- api- auth 更名为 @ ewsjs/ xhr

其他相关的 libs 也将移动到 @ewsjs scope/org

> 1.3.0带来多处变化,新api和代理支持. 这也是使用流行的重写 `request` 软件包

## 3.1.2 国家

-   Axios 的固定代理问题

## 3.1.1 国家

-   固定响应

## 3.1.0 (中文(简体) )

-   更新依赖关系

## 3.0.0 (单位:千美元)

-   更新 `@ewsjs/ntlm-client` 改为 `3.0.0` 以 ntlm 修正节点 18+ 问题

## 2.0.0 (韩语)

-   删除已贬值的 xhr apis (`cookieAuthXhrApi`, (中文(简体) ), `ntlmAuthXhrApi`, (中文(简体) ), `proxySupportedXhrApi`) (中文(简体) ).
-   删除对 `request`, (中文(简体) ), `bluebird` 财务报告和审定财务报表 `fetch`。 。 。 .

## 1.5.0 (中文(简体) )

#15 在流中使用预调选项

# 安装

`npm install @ewsjs/xhr --save`

# 怎么样

> 公共方法 `useProxy`, (中文(简体) ), `useNtlmAuthentication` 财务报告和审定财务报表 `useCookieAuthentication` 返回链条示例.

```ts
// import 
import { ......,  ConfigurationApi } from "ews-javascript-api";
import { XhrApi } from "@ewsjs/xhr";

// create instance
let xhr = new XhrApi({ headers: { 'custom-header': 'value' }, rejectUnauthorized: false})
    .useCookieAuthentication(credentials.userName, credentials.password)
    .useProxy("http://squidorOtherProxyServer:3128", "proxyUser", "password");

// alternatively 
let xhr = new XhrApi({ headers: { 'custom-header': 'value' }, rejectUnauthorized: false});
xhr.useCookieAuthentication(credentials.userName, credentials.password);
xhr.useProxy("http://squidorOtherProxyServer:3128", "proxyUser", "password");

// use in ews-javascript-api
ConfigurationApi.ConfigureXHR(xhr);
```

## 构造器

```ts
/**
 * Creates an instance of XhrApi optionally passing options for request
 * @memberof XhrApi
 */
new XhrApi();
/**
 * Creates an instance of XhrApi optionally passing options for request
 * @param {CoreOptions} requestOptions Options for request
 * @memberof XhrApi
 */
new XhrApi(requestOptions: CoreOptions); // CoreOptions is from @types/request, part of request pkg
/**
 * Creates an instance of XhrApi. optionally pass true to bypass remote ssl/tls certificate check
 * @param {boolean} allowUntrustedCertificate whether to allow non trusted certificate or not
 * @memberof XhrApi
 */
new XhrApi(allowUntrustedCertificate: boolean);
```

## 代理服务器支持

```ts
import { XhrApi } from "@ewsjs/xhr";

// without proxy credential
let xhr = new XhrApi({ headers: { 'custom-header': 'value' }, rejectUnauthorized: false})
    .useProxy("http://squidorOtherProxyServer:3128");

// with proxy credential
let xhr = new XhrApi({ headers: { 'custom-header': 'value' }, rejectUnauthorized: false})
    .useProxy("http://squidorOtherProxyServer:3128", "proxyUser", "password");
```

## 添加 Ntlm 认证( 或使用 EWS 的 Windows 集成认证)

```ts
import { XhrApi } from "@ewsjs/xhr";
let xhr = new XhrApi()
    .useNtlmAuthentication(credentials.userName, credentials.password);
```

## 添加 cookie 认证( 使用 TMG/ ISA)

```ts
import { XhrApi } from "@ewsjs/xhr";
let xhr = new XhrApi({ rejectUnauthorized: false})
    .useCookieAuthentication(credentials.userName, credentials.password);
```

### 使用带有 cookie 认证的代理

```ts
import { XhrApi } from "@ewsjs/xhr";
let xhr = new XhrApi(true)
    .useCookieAuthentication(credentials.userName, credentials.password)
    .useProxy("http://squidorOtherProxyServer:3128", "proxyUser", "password");
```

## 信息: Ntlm 没有代理支持( yet !)

在Ntlm与代理使用之前,有些问题需要解决,但无论怎样,这种局面在公司环境中都是非常需要的.

## 许可证

麻省理工学院

### 1.1.1 变动

-   固定头检查为大小写不敏感
-   将页眉帮助方法创建到 util.js

## 常见问题

### @ewsjs/xhr 是什么？

用于ewsjs的其他 XHR 方法

### 如何安装 @ewsjs/xhr？

在项目目录运行 npm install @ewsjs/xhr，或使用 pnpm add / yarn add / bun add。

### @ewsjs/xhr 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @ewsjs/xhr 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @ewsjs/xhr 可以商用吗？

@ewsjs/xhr 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @ewsjs/xhr 的下载量有多少？

根据 npm 官方下载统计，@ewsjs/xhr 在 2026/10/14 – 2026/11/12 这 30 天内被下载 241,591 次，日均约 8,053 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @ewsjs/xhr 还在维护吗？

最新版本 3\.1\.3 发布于 2024/05/13（2 年前）；至今共发布 17 个版本，其中过去 12 个月发布了 0 个；首次发布于 2018/05/02。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

