一旦设置了Erlang httpc客户端默认配置文件,如何取消设置或删除代理选项?

一旦设置了Erlang httpc客户端默认配置文件,如何取消设置或删除代理选项?,erlang,http-proxy,httpc,Erlang,Http Proxy,Httpc,代理最初未设置并显示为未定义: httpc:get_options(all). {ok,[{proxy,{undefined,[]}}, {https_proxy,{undefined,[]}}, {pipeline_timeout,0}, {max_pipeline_length,2}, {max_keep_alive_length,5}, {keep_alive_timeout,120000}, {max_sessions,2},

代理最初未设置并显示为未定义:

httpc:get_options(all).
{ok,[{proxy,{undefined,[]}},
     {https_proxy,{undefined,[]}},
     {pipeline_timeout,0},
     {max_pipeline_length,2},
     {max_keep_alive_length,5},
     {keep_alive_timeout,120000},
     {max_sessions,2},
     {cookies,disabled},
     {verbose,false},
     {ipfamily,inet},
     {ip,default},
     {port,default},
     {socket_opts,[]},
     {unix_socket,undefined}]}
我可以毫无问题地设置代理选项:

httpc:set_options([{proxy, {{"www-proxy.mycompany.com", 8000},["localhost"]}}]).
当不需要代理时,如何将其取消设置为未定义(或无代理)?我试过:

httpc:set_options([{proxy,{undefined, []}}]).
But it throws an exception:
** exception throw: {error,{bad_option,proxy,{undefined,[]}}}
     in function  httpc:bad_option/2 (httpc.erl, line 1102)
     in call from httpc:validate_options/2 (httpc.erl, line 932)
     in call from httpc:validate_options/1 (httpc.erl, line 922)
     in call from httpc:set_options/2 (httpc.erl, line 236)

我做错了什么?

你做错了什么,这是传递给函数的参数格式。正确的格式是

httpc:set_options([{proxy, {{"", 0},[]}}]).
现在代理主机将为“”:0。但我不知道你的任务是否可以接受

对评论的答复: 尝试将“代理”选项直接设置到http_manager,而不是杀死他:

httpc_manager:set_options([{proxy,{undefined, []}}],httpc_manager).
看看erlang shell:

1> inets:start().
ok
2> httpc:set_options([{proxy, {{"www-proxy.mycompany.com", 8000},["localhost"]}}]).
ok
3> httpc:get_options(all).
{ok,[{proxy,{{"www-proxy.mycompany.com",8000},
             ["localhost"]}},
     {https_proxy,{undefined,[]}},
     {pipeline_timeout,0},
     {max_pipeline_length,2},
     {max_keep_alive_length,5},
     {keep_alive_timeout,120000},
     {max_sessions,2},
     {cookies,disabled},
     {verbose,false},
     {ipfamily,inet},
     {ip,default},
     {port,default},
     {socket_opts,[]},
     {unix_socket,undefined}]}
4> httpc_manager:set_options([{proxy,{undefined, []}}],httpc_manager).
ok
5> httpc:get_options(all).                                            
{ok,[{proxy,{undefined,[]}},
     {https_proxy,{undefined,[]}},
     {pipeline_timeout,0},
     {max_pipeline_length,2},
     {max_keep_alive_length,5},
     {keep_alive_timeout,120000},
     {max_sessions,2},
     {cookies,disabled},
     {verbose,false},
     {ipfamily,inet},
     {ip,default},
     {port,default},
     {socket_opts,[]},
     {unix_socket,undefined}]}

错误之处在于传递给函数的参数格式。正确的格式是

httpc:set_options([{proxy, {{"", 0},[]}}]).
现在代理主机将为“”:0。但我不知道你的任务是否可以接受

对评论的答复: 尝试将“代理”选项直接设置到http_manager,而不是杀死他:

httpc_manager:set_options([{proxy,{undefined, []}}],httpc_manager).
看看erlang shell:

1> inets:start().
ok
2> httpc:set_options([{proxy, {{"www-proxy.mycompany.com", 8000},["localhost"]}}]).
ok
3> httpc:get_options(all).
{ok,[{proxy,{{"www-proxy.mycompany.com",8000},
             ["localhost"]}},
     {https_proxy,{undefined,[]}},
     {pipeline_timeout,0},
     {max_pipeline_length,2},
     {max_keep_alive_length,5},
     {keep_alive_timeout,120000},
     {max_sessions,2},
     {cookies,disabled},
     {verbose,false},
     {ipfamily,inet},
     {ip,default},
     {port,default},
     {socket_opts,[]},
     {unix_socket,undefined}]}
4> httpc_manager:set_options([{proxy,{undefined, []}}],httpc_manager).
ok
5> httpc:get_options(all).                                            
{ok,[{proxy,{undefined,[]}},
     {https_proxy,{undefined,[]}},
     {pipeline_timeout,0},
     {max_pipeline_length,2},
     {max_keep_alive_length,5},
     {keep_alive_timeout,120000},
     {max_sessions,2},
     {cookies,disabled},
     {verbose,false},
     {ipfamily,inet},
     {ip,default},
     {port,default},
     {socket_opts,[]},
     {unix_socket,undefined}]}

我想我可以一直使用:exit(whereis(httpc_管理器),kill)。让主管重新做一个。但我希望能找到一种方法来清除代理信息而不必杀死它。我想我总是可以使用:exit(whereis(httpc_manager),kill)。让主管重新做一个。但是我们希望能够在不杀死代理信息的情况下清除代理信息。是的,查看代码,他们正在查找{{::list(),::non_neg_integer()},::list()},就像您所指出的那样。但我不确定这个建议是否有效。它是否等同于没有代理集?它可能试图走到任何地方。我会试试,看看会发生什么。我很快会回来的。那不起作用。我发现的唯一解决方法是在需要重置代理时使用exit(whereis(httpc_manager),kill)杀死httpc管理器。它从未定义的代理设置开始。我在回答中添加了其他解决方案。现在行了吗?行了,行了!我还必须为https\u代理添加重置。e、 httpc_管理器:设置_选项([{https_proxy,{undefined,[]}],httpc_管理器)。是的,查看代码,他们正在查找{{::list(),::non_neg_integer()},::list()},如您所示。但我不确定这个建议是否有效。它是否等同于没有代理集?它可能试图走到任何地方。我会试试,看看会发生什么。我很快会回来的。那不起作用。我发现的唯一解决方法是在需要重置代理时使用exit(whereis(httpc_manager),kill)杀死httpc管理器。它从未定义的代理设置开始。我在回答中添加了其他解决方案。现在行了吗?行了,行了!我还必须为https\u代理添加重置。e、 httpc_管理器:设置_选项([{https_代理,{undefined,[]}],httpc_管理器)。