简体   繁体   English

使用 .net/c# 通过代理连接到 Watson DiscoveryService

[英]Connect to Watson DiscoveryService through a proxy using .net/c#

Can't connect to Watson Discovery Service while behind a corporate proxy, using C#使用 C# 在公司代理后面时无法连接到 Watson Discovery Service

I read the documentation, and searched online but only a reference to a NodeJS based implementation.我阅读了文档,并在线搜索,但仅引用了基于 NodeJS 的实现。 There was also someone looking for a solution to the same problem but using Java, and what was proposed was to extend the current api to add a method to support proxy.也有人在寻找相同问题的解决方案,但使用 Java,提出的是扩展当前的 api 以添加支持代理的方法。

 IamAuthenticator authenticator = new IamAuthenticator(
     apikey: "{apikey}"
     );

 DiscoveryService discovery = new DiscoveryService("2019-04-30", authenticator);
 discovery.SetServiceUrl("{url}");

 var result = discovery.CreateEnvironment(
     name: "my_environment",
     description: "My environment"
     );

 Console.WriteLine(result.Response);

The code above comes straight for the documentation and it works fine, as long as I'm not behind a proxy.上面的代码直接用于文档,只要我不在代理后面,它就可以正常工作。 I want to know if I'm missing something or Watson .net SDK doesn't support proxies.我想知道我是否遗漏了什么或 Watson .net SDK 不支持代理。 I already asked in IBM developer forum but no answers.我已经在 IBM 开发者论坛上问过了,但没有答案。

Did you try to set proxies argument?您是否尝试设置代理参数? This is the python version, but maybe这是 python 版本,但也许

proxies={'proxies.https' : 'your_proxy', 'proxies.http' : 'your_proxy'}

You should be able to set the proxy via http_proxy or https_proxy environment variable.您应该能够通过http_proxyhttps_proxy环境变量设置代理。 You can set this in the application environment using您可以在应用程序环境中使用

set http_proxy=http://proxy.server.com:3128

from cmd.来自 cmd。

You can also set this in the application using您也可以在应用程序中使用

Environment.SetEnvironmentVariable("http_proxy", "http://proxy.server.com:3128");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM