如何PowerShell会话中设置代理

背景

由于众所周知的原因,github的访问一直不太顺畅。

1
2
PS [GIT_REPO]> git push
fatal: unable to access 'https://github.com/AxisRay/AxisRay.github.io.git/': Failed to connect to github.com port 443 after 21141 ms: Timed out

在Bash中,我们可以通过如下命令来为HTTPSHTTP设置代理。

1
2
export HTTP_PROXY=http://127.0.0.1:1080
export HTTPS_PROXY=http://127.0.0.1:1080

而在Windows下,PowerShell会话中也有类似的设置方式。

设置方法

1
2
$env:HTTP_PROXY = "http://127.0.0.1:1080"
$env:HTTPS_PROXY = "http://127.0.0.1:1080"

Boom!

1
2
3
4
5
6
7
8
9
10
PS [GIT_REPO]> git push
Enumerating objects: 23, done.
Counting objects: 100% (23/23), done.
Delta compression using up to 8 threads
Compressing objects: 100% (11/11), done.
Writing objects: 100% (14/14), 8.09 KiB | 1.62 MiB/s, done.
Total 14 (delta 7), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (7/7), completed with 5 local objects.
To https://github.com/AxisRay/AxisRay.github.io.git
b582b44..90e06b5 source -> source

从光盘或镜像中安装.NetFramework

windows8预装了.Net Framework4.0,但是4.0并不会向下兼容使用更早.Net版本编写的程序。当我们运行一个使用更早版本编写的.Net程序时,Windows会自动帮我们下载并安装.Net Framework3.5。但是当遇到没有网络或者网速比较慢的时候就比较难受了。所以我们可以选择从Windows8光盘或者镜像安装.
假设光盘或光盘镜像的盘符为X,在命令提示符中输入

1
DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:X:\sources\sxs

NetFx3