node.js - npm install 在一个代理后面但得到 Http Error=407(Forefront TMG 需要授权)
问题描述
我的笔记本用的是MacOS,已经在Network Preferences里面设置了http(s)代理,但是在终端运行的时候总是安装包失败npm install
,就弹出了错误407 Proxy Authentication Required
。
所以我安装了cntlm并应用了正确的配置。
下面是测试,它似乎通过了(返回 HTTP 代码 200):
cntlm -c /usr/local/etc/cntlm.conf -I -M http://registry.npmjs.org/vue
Password:
Config profile 1/4... OK (HTTP code: 200)
----------------------------[ Profile 0 ]------
Auth NTLMv2
PassNTLMv2 28B089518C6573274C6B9D83D0XXXXXX
当我运行npm i vue-cli -g
时,cntlm确实收到了如下请求:
cntlm -c /usr/local/etc/cntlm.conf -f
Oct 15 15:12:29 cntlm[17646] <Info>: Cntlm ready, staying in the foreground
Oct 15 15:12:38 cntlm[17646] <Info>: Using proxy company-proxy:80
Oct 15 15:12:38 cntlm[17646] <Debug>: 127.0.0.1 GET http://registry.npmjs.org/nexe
但是nodejs抛出了以下异常:
npm i vue-cli -g
npm ERR! code E407
npm ERR! 407 Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. ): vue-cli@latest
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/****/.npm/_logs/2018-10-15T23_13_47_019Z-debug.log
这让我很困惑:因为测试通过了,但是为什么cntlm仍然无法连接到 npmjs.org?
解决方案
最后找出解决方案:
不要使用纯文本密码
#
(在行首添加一个Password
,例如更改Password XXX
为#Password XXX
)请改用PassLM、PassNT、PassNTLMv2(似乎哈希值会再次阻止身份验证握手机制,这应该意味着您代表已登录 Windows 用户帐户的应用程序)。
默认的 cntlm 配置文件已经介绍了如何生成它们的步骤。
我的步骤如下:
执行
cntlm -H -d your_domain -u your_username
然后它会提示密码,填写您的密码,然后按 Enter:
输出将如下所示:
Password:
PassLM F5314AF8A2DB16BDB7EE9FA6CFC5BC9A
PassNT 4EC02E0D65F8F0C1A9386C69CB6A2555
PassNTLMv2 28B089518C6573274C6B9D83D0EB8651
将上述哈希值粘贴到配置文件中的相关字段。
保存然后重新启动cntlm,它可以工作。
推荐阅读
- spring-boot - 如何在 Spring Boot Controller Test 中注入接口?
- visual-studio - 如何使用 Visual Studio 将文件夹添加到已复制到本地 git 存储库的 git 源代码控制?
- java - Java:检测 csv 或 txt 文件的分隔符
- jmeter - 执行系统调用时发生异常 JMeter OS Sampler 错误
- django - Django多对多字段默认
- python - 如何将记事本++文件中的列导出为csv文件格式
- python - 我有一个数据框,我想从名为 requester 的列中获取值我得到一个额外的列以及 requester 列
- android - 选择 SDK:请提供 Android SDK 的路径
- c# - 从 C# 中的 dll 调用程序中的方法
- ios - 如何在ios中创建没有tableview和collection view的行