Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
558 views
in Technique[技术] by (71.8m points)

java - Java上的电报bot无法与代理一起使用(Telegram bot on Java not working with proxy)

       try {

           // Create the Authenticator that will return auth's parameters for proxy authentication
           Authenticator.setDefault(new Authenticator() {
               @Override
               protected PasswordAuthentication getPasswordAuthentication() {
                   return new PasswordAuthentication(PROXY_USER, PROXY_PASSWORD.toCharArray());
               }
           });


       ApiContextInitializer.init();
       TelegramBotsApi telegramBotsApi = new TelegramBotsApi();

       // Set up Http proxy
       DefaultBotOptions botOptions = ApiContext
               .getInstance(DefaultBotOptions.class);


       botOptions.setProxyHost(PROXY_HOST);
       botOptions.setProxyPort(PROXY_PORT);
       //Select proxy type: [HTTP|SOCKS4|SOCKS5] (default: NO_PROXY)
       botOptions.setProxyType(DefaultBotOptions.ProxyType.HTTP);

       telegramBotsApi.registerBot(new MyBot(BOT_TOKEN, BOT_NAME, botOptions));
       } catch (TelegramApiException e) {
       //    e.printStackTrace();
       }
   }  

it is my main method, but i get next error: *

(这是我的主要方法,但出现下一个错误: *)

Exception in thread "main" java.lang.InternalError: Should not reach here at java.net.HttpConnectSocketImpl.doTunneling(HttpConnectSocketImpl.java:181) at java.net.HttpConnectSocketImpl.doTunnel(HttpConnectSocketImpl.java:168) at java.net.HttpConnectSocketImpl.access$200(HttpConnectSocketImpl.java:44) at org.telegram.telegrambots.util.WebhookUtils.clearWebhook(WebhookUtils.java:74) at org.telegram.abilitybots.api.bot.AbilityBot.clearWebhook(AbilityBot.java:42) at org.telegram.telegrambots.meta.TelegramBotsApi.registerBot(TelegramBotsApi.java:120) at Main.main(Main.java:49) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at java.net.HttpConnectSocketImpl.doTunneling(HttpConnectSocketImpl.java:179) ..

(线程“主”中的异常java.lang.InternalError:不应在java.net的java.net.HttpConnectSocketImpl.doTunneling(HttpConnectSocketImpl.java:181)到达此处。在java.net的HttpConnectSocketImpl.doTunnel(HttpConnectSocketImpl.java:168)在org.telegram.telegrambots.util.WebhookUtils.clearWebhook(WebhookUtils.java:74)处的.HttpConnectSocketImpl.access $ 200(HttpConnectSocketImpl.java:44)在org.telegram.abilitybots.api.bot.AbilityBot.clearWebhook(AbilityBot.java: 42)位于Main.main(Main.java:49)的org.telegram.telegrambots.meta.TelegramBotsApi.registerBot(TelegramBotsApi.java:120)造成原因:sun.reflect.NativeMethodAccessorImpl.invoke0处的java.lang.reflect.InvocationTargetException (本地方法)位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)位于sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)位于java.lang.reflect.Method.invoke(Method.java:498) )在java.net.HttpConnectSocketImpl.doTunneling(HttpConnectSocketImpl.java:179)..)

. 27 more Caused by: java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(StringTokenizer.java:349) at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2072) ... 32 more

(。27更多原因:sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2072)上的java.util.StringTokenizer.nextToken(StringTokenizer.java:349)处的java.util.NoSuchElementException ...另外32个)

*

(*)

my proxy is working, I checked, but i dont know what problem is.

(我的代理正在工作,我检查了一下,但是我不知道是什么问题。)

When i deployed this code to heroku, it is working.

(当我将此代码部署到heroku时,它正在工作。)

Help me please

(请帮帮我)

  ask by Tanya Vinyar translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...