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

查看:314
本文介绍了通过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,但是手册并没有说明关于登录部分的任何内容,所以我都尝试过:

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/zh-cn/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_PROXY FTP_PROXY 或<$ c $的变量c> HTTPS_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命令提示符处执行的所有后续命令将能够通过代理以及提供的身份验证访问Internet。

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天全站免登陆