【问题标题】:Ionic 3 Push Notification Error "statusText":"Unknown Error","name":"HttpErrorResponse","message":"Http failure response for (unknown url)Ionic 3 推送通知错误 "statusText":"Unknown Error","name":"HttpErrorResponse","message":"(未知 url)的 Http 失败响应
【发布时间】:2018-11-20 20:24:22
【问题描述】:

我在 Wordpress 4.9.8 上使用 Ionic 3 和后端,并按照指南进行推送通知:https://www.delitestudio.com/it/wordpress/push-notifications-for-wordpress/documentation/#configurePushNotificationsForWordPress

我在第 4.1 点,我写了这个:

export class NotifyPushProvider {

  private url="https://backendcomics.netsons.org/pnfw/register/";

  constructor(private push : Push, private http : HttpClient) {}

  register(){
      if(!isCordovaAvailable()){
        console.error('NotifyPush is off: cordova is not available');
        return;
      }else
          console.log('NotifyPush is on!');

      this.push.hasPermission()
          .then((res: any) => {
              if (res.isEnabled) {
                  console.log('We have permission to send push notifications');
              } else {
                  console.log('We do not have permission to send push notifications');
              }
          });


      this.push.createChannel({
          id: "900606371725-kt3b1chjppmhug88i7r306oivmu4qtd4.apps.googleusercontent.com",
          description: "My first test channel",
          // The importance property goes from 1 = Lowest, 2 = Low, 3 = Normal, 4 = High and 5 = Highest.
          importance: 3
      }).then(() => console.log('Channel created'));

      const options: PushOptions = {
          android: {
              vibrate :true,
              sound: 'false'
          },
          ios: {
              alert: 'true',
              badge: true,
              sound: 'false'
          },
          windows: {},
          browser: {
              pushServiceURL: this.url
          }
      };


      const pushObject: PushObject = this.push.init(options);


      pushObject.on('notification').subscribe((notification: any) => console.log('Received a notification', notification));

      pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));

      pushObject.on('registration').subscribe((registration: any) => {
          console.log('Device registered', JSON.stringify(registration))
          let x : number = new Date().getTime()
          console.log("Timestamp: "+x);

          console.log("post call")
          this.http.post(this.url,
              "oauth_consumer_key=ck_6fde6b6315c6b6646f45dbd2beec6ff5" +
              "&oauth_timestamp=" + x +
              "&oauth_nonce=" + x + "abc" +
              "&os=Android" +
              "&token=tokenless_" + x,
              {headers: {"Content-Type": "application/x-www-form-urlencoded",
                        "Access-Control-Allow-Origin": "https://backendcomics.netsons.org",
                        "Access-Control-Allow-Methods": "POST",
                        "Access-Control-Allow-Headers": "Content-Type"}}
          ).subscribe((data) => console.log("Post data:" + JSON.stringify(data)), error => console.error("Post error: " + JSON.stringify(error)));

          /*console.log("get call")
          this.http.get("https://backendcomics.netsons.org/pnfw/posts?" +
              "os=Android" +
              "&token=tokenless_" + x,
              {headers: {"Content-Type": "application/x-www-form-urlencoded"}}
          ).subscribe((data) => console.log("GET data:" + JSON.stringify(data)), error => console.error("GET error: " + JSON.stringify(error)));
*/
      });
    }
}

但在回复后我收到错误:

Post error: {"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":null,"ok":false,"name":"HttpErrorResponse","message":"Http failure response for (unknown url): 0 Unknown Error","error":{"isTrusted":true}}

还有这个警告:

Bloccata richiesta multiorigine (cross-origin): il criterio di corrispondenza dell’origine non consente la lettura della risorsa remota da https://backendcomics.netsons.org/pnfw/register/. Motivo: richiesta preliminare (“preflight”) del canale CORS non riuscita.[Ulteriori informazioni]

Bloccata richiesta multiorigine (cross-origin): il criterio di corrispondenza dell’origine non consente la lettura della risorsa remota da https://backendcomics.netsons.org/pnfw/register/. Motivo: richiesta CORS non riuscita.[Ulteriori informazioni]

【问题讨论】:

  • 查找 CORS 问题以及如何解决它
  • @ehacinom 我安装了高级 http 插件并使用它而不是 HttpClient 但现在我在 .../pnfw/register/keys 上遇到了同样的错误
  • @ehacinom 好的,现在它说 oauth_signature 丢失了......它的价值是什么?

标签: wordpress ionic-framework notifications push phonegap-plugins


【解决方案1】:

我用 OneSignal 代替这个很容易解决了这个问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多