设置后如何取消或删除 Erlang httpc 客户端默认配置文件上的代理选项?
How to unset or remove the proxy option on Erlang httpc client default profile once set?
原先未设置代理,显示未定义:
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。但是我不知道你的任务是否可以接受。
回复评论:
尝试将 'proxy' 选项直接设置为 http_manager 而不是杀死他:
httpc_manager:set_options([{proxy,{undefined, []}}],httpc_manager).
看看二郎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: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。但是我不知道你的任务是否可以接受。
回复评论: 尝试将 'proxy' 选项直接设置为 http_manager 而不是杀死他:
httpc_manager:set_options([{proxy,{undefined, []}}],httpc_manager).
看看二郎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}]}