How to send Huawei push notification through Proxy using Java

633 views Asked by At

How to send push notification for Huawei devices using Java through proxy server

    HttpPost httpPost = new HttpPost(this.HcmPushUrl);
    StringEntity entity = new StringEntity(JSON.toJSONString(map), "UTF-8");
    httpPost.setHeader("Authorization", "Bearer " + accessToken);
    httpPost.setHeader("Content-Type", "application/json;charset=utf-8");
    httpPost.setEntity(entity);
    CloseableHttpResponse response = httpClient.execute(httpPost);
    String rpsContent = EntityUtils.toString(response.getEntity());

Which is something similar to ProxyManager.setProxy(proxyAddress, proxyPort) of APNS call.

1

There are 1 answers

1
zhangxaochen On BEST ANSWER

Please kindly refer to the following code:

HuaweiCredential credential = HuaweiCredential.builder()
.setAppId(appId)
.setAppSecret(appSecret)
.setHttpClient()//set your own http client with proxy here
.build();

// Create HuaweiOption
HuaweiOption option = HuaweiOption.builder()
.setCredential(credential)
.setHttpClient()//set your own http client with proxy here
.build();

HMS Pushkit Java Severdemo On Github