通过windows命令行设置代理,包括登录参数 [英] Set proxy through windows command line including login parameters

查看:39
本文介绍了通过windows命令行设置代理,包括登录参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过命令行设置代理,我发现的第一件事是您必须以管理员权限运行命令行 - 那么基本的代理设置将是:

I want to set a proxy throught the command line, first thing I found out is that you have to run command line with administrator rights - then the basic proxy set would be:

netsh winhttp set proxy SERVER:PORT

这很好用,但我还想添加一个登录名.正如你所看到的,我已经尝试过使用 netsh->winhttp,但是 manual 没有说关于登录部分的任何信息,所以我只是尝试:

This works nice, but I also want to add a login. As you can see I've tried using netsh->winhttp, however manual does not say anything about the login part so I just tried:

netsh winhttp set proxy user:password@SERVER:PORT

不幸的是,这不起作用.甚至可以在 netsh->winhttp 中实现这样的功能吗?

This unfortunately does not work. Is it even possible to achieve something like this in netsh->winhttp?

如果是这样,怎么办?如果不是 => 我应该遵循哪些 Windows 命令?结果,或这是更容易̶a̶c̶h̶i̶e̶v̶e̶a̶b̶l̶e̶通过一些WINDOWSAPI̶(例如,使用C/C + +̶̶)̶?̶

If so, how? If not => what windows commands should I follow?
̶O̶r̶ ̶i̶s̶ ̶t̶h̶i̶s̶ ̶m̶o̶r̶e̶ ̶e̶a̶s̶i̶l̶y̶ ̶a̶c̶h̶i̶e̶v̶e̶a̶b̶l̶e̶ ̶t̶h̶r̶o̶u̶g̶h̶ ̶s̶o̶m̶e̶ ̶W̶i̶n̶d̶o̶w̶s̶A̶P̶I̶ ̶(̶e̶.̶g̶.̶ ̶u̶s̶i̶n̶g̶ ̶C̶/̶C̶+̶+̶)̶?̶

感谢您的帮助,如有任何不清楚的地方,请随时提问.

Thanks for help, please feel free to ask any questions if something is unclear.

使用:Windows 7、cmd.exe、netsh->winhttp

这看起来像 C++ 方式:http://msdn.microsoft.com/en-us/library/windows/desktop/aa383144(v=vs.85).aspx ,但 C++ 的更好方法可能是走这条路:http://msdn.microsoft.com/en-us/library/windows/desktop/aa385384(v=vs.85).aspx#general_option, - 所以剩下的问题是如何在命令行中实现这一点(或者更好的命令 -行->netsh->winhttp)?

This looks like the C++ way: http://msdn.microsoft.com/en-us/library/windows/desktop/aa383144(v=vs.85).aspx , but a better way for C++ might be to go this way: http://msdn.microsoft.com/en-us/library/windows/desktop/aa385384(v=vs.85).aspx#general_option, - so the remaining question is how to achieve this in command line generally (or even better command-line->netsh->winhttp)?

推荐答案

如果您使用的是 Microsoft Windows 环境,那么您可以设置一个名为 HTTP_PROXYFTP_PROXYHTTPS_PROXY 取决于要求.

If you are using Microsoft windows environment then you can set a variable named HTTP_PROXY, FTP_PROXY, or HTTPS_PROXY depending on the requirement.

我使用了以下设置来允许我在 windows 命令提示符下的命令使用浏览器代理访问互联网.

I have used following settings for allowing my commands at windows command prompt to use the browser proxy to access internet.

set HTTP_PROXY=http://proxy_userid:proxy_password@proxy_ip:proxy_port

右边的参数必须用实际值替换.

The parameters on right must be replaced with actual values.

一旦设置了变量 HTTP_PROXY,我们在 windows 命令提示符下执行的所有后续命令都将能够通过代理以及提供的身份验证访问互联网.

Once the variable HTTP_PROXY is set, all our subsequent commands executed at windows command prompt will be able to access internet through the proxy along with the authentication provided.

此外,如果您想使用 ftp 和 https 以及使用相同的代理,那么您可能也喜欢以下环境变量.

Additionally if you want to use ftp and https as well to use the same proxy then you may like to the following environment variables as well.

set FTP_PROXY=%HTTP_PROXY%

set HTTPS_PROXY=%HTTP_PROXY%

这篇关于通过windows命令行设置代理,包括登录参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆