如何使用Java通过代理发送华为推送通知

huangapple go评论68阅读模式
英文:

How to send Huawei push notification through Proxy using Java

问题

如何通过代理服务器使用Java向华为设备发送推送通知

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());

这与APNS调用中的ProxyManager.setProxy(proxyAddress, proxyPort)类似
英文:

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

得分: 1

请参考以下代码:

HuaweiCredential credential = HuaweiCredential.builder()
.setAppId(appId)
.setAppSecret(appSecret)
.setHttpClient()//在这里设置您自己的带有代理的 http 客户端
.build();

// 创建 HuaweiOption
HuaweiOption option = HuaweiOption.builder()
.setCredential(credential)
.setHttpClient()//在这里设置您自己的带有代理的 http 客户端
.build();

HMS Pushkit Java 服务器演示位于 Github

英文:

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

huangapple
  • 本文由 发表于 2020年9月29日 02:16:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/64107509.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定