内网通过代理方式访问外网问题

lifeontrip
2017-07-07 09:45 3.5k 0

配置代理,无法访问到极光

1.内网服务器是linux服务器
2.在"/etc/profile"文件配置代理信息如下
export http_proxy=http://代理用户名:密码@220.166.240.78:8118
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export no_proxy="localhost,127.0.0.1,.huawei.com"
3.在内网服务器上使用命令“curl”可以访问到极光服务器
4.java代码实现如下

**HttpProxy proxy=new HttpProxy(host, port, user, pwd);**
**          **
**JPushClient jpushClient = new JPushClient((String)PropertiesPlugin.getParamMapValue(ConstantInit.JIGUANG_MASTER_SECRET),**
**        (String)PropertiesPlugin.getParamMapValue(ConstantInit.JIGUANG_APP_KEY), proxy, config);**

**String authCode = ServiceHelper.getBasicAuthorization((String)PropertiesPlugin.getParamMapValue(ConstantInit.JIGUANG_APP_KEY), (String)PropertiesPlugin.getParamMapValue(ConstantInit.JIGUANG_MASTER_SECRET));**
**ApacheHttpClient httpClient = new ApacheHttpClient(authCode, proxy, config);**
**jpushClient.getPushClient().setHttpClient(httpClient);**

**try {**
**     **
**    **
**    // For push, all you need do is to build PushPayload object.**
**    **
**    PushPayload.Builder payload = //buildPushObjectAll(alertmsg);**
**            PushPayload.newBuilder()**
**            .setPlatform(Platform.android())**
**            .setAudience(Audience.alias(terminalImei.toArray(new String[]{})));**
**    **
**    if(TerminalStatus.Fresh.name().equals(noticeType)){**
**         payload.setMessage(Message.newBuilder()**
**                    .setMsgContent(noticeType)**
**                    .setTitle(noticeType)**
**                    .addExtra("type", noticeType)**
**                    .addExtra("dblink",(String) PropertiesPlugin.getParamMapValue(ConstantInit.DB_LINK_DEFAULT))**
**                    .addExtra("task", "test fresh message")**
**                    .addExtra("resultMessage", "")**
**                    .build());//设置消息**
**    }else{**
**        payload.setNotification(Notification.newBuilder()**
**                .setAlert(noticeType)**
**                .addPlatformNotification(AndroidNotification.newBuilder()**
**                        .setTitle(noticeType)**
**                        .addExtra("type", noticeType)**
**                        .addExtra("dblink",(String) PropertiesPlugin.getParamMapValue(ConstantInit.DB_LINK_DEFAULT))**
**                        .addExtra("task", noticeData)**
**                        .addExtra("resultMessage", "")**
**                        .build())**
**                        .build());//设置通知**
**    }**
**   **
**    **
**    PushResult result = jpushClient.sendPush(payload.build());**

5.在内网服务器测试包异常,异常信息如下

_JfinalUIB-V2 2017-07-07 15:07:50.379 ERROR [DefaultQuartzScheduler_Worker-1] <cn.jiguang.common.connection.ApacheHttpClient.processResponse(ApacheHttpClient.java:367)> Unexpected response._
_JfinalUIB-V2 2017-07-07 15:07:50.380 ERROR [DefaultQuartzScheduler_Worker-1] <com.huawei.ywzljc.util.JobDeal.noticeByJpush(JobDeal.java:441)> 1234JobDeal.noticeByJpush——APIRequestException: _
_{}_
_    at cn.jiguang.common.connection.ApacheHttpClient.processResponse(ApacheHttpClient.java:370)_
_    at cn.jiguang.common.connection.ApacheHttpClient.sendPost(ApacheHttpClient.java:274)_
_    at cn.jpush.api.push.PushClient.sendPush(PushClient.java:169)_
_    at cn.jpush.api.JPushClient.sendPush(JPushClient.java:194)_
_    at com.huawei.ywzljc.util.JobDeal.noticeByJpush(JobDeal.java:434)_
_    at com.huawei.ywzljc.util.JobDeal.notice4Phone(JobDeal.java:323)_
_    at com.huawei.ywzljc.util.JobDeal.execute(JobDeal.java:55)_
_    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)_
_    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)_

1个回答

热门排序