2016-05-12 22 views
0

次のコードを使用して、Firefoxに通知を送信できます。正常に動作しています。Javaを使用してFirefoxブラウザにプッシュ通知を送信する方法

public static void main(String args[]){ 
      HttpClient httpClient = new DefaultHttpClient(); 
      try { 
       String furl = "https://updates.push.services.mozilla.com/push/v1/gAAAAABXM0VF8ptA2Tl38W4b9g9Dpm0Ek2G1ZTztq0USYSYKiOicOkcB0XEewj_Oh0UnwRbia8mMxmfoWL1kyw4ix5PKFS943hYbOo-PGqpPe7qkp4GYC4wk2Mk8Yy1Yyuj6FhM_S-ec"; 

       HttpPut request = new HttpPut(furl); 
       HttpResponse response = httpClient.execute(request); 

       Integer responseCode = response.getStatusLine().getStatusCode(); 
       System.out.println(responseCode); 
      }catch(Exception e){ 
       e.printStackTrace(); 
      } 
     } 

しかし、私は、Firefoxに送信するタイトル、本文、URLのuanbleを送信しようとしています。私は400として応答コードを取得しています

 public static void main(String args[]){ 
      HttpClient httpClient = new DefaultHttpClient(); 
      try { 
    String furl = "https://updates.push.services.mozilla.com/push/v1/gAAAAABXM0VF8ptA2Tl38W4b9g9Dpm0Ek2G1ZTztq0USYSYKiOicOkcB0XEewj_Oh0UnwRbia8mMxmfoWL1kyw4ix5PKFS943hYbOo-PGqpPe7qkp4GYC4wk2Mk8Yy1Yyuj6FhM_S-ec"; 
       JSONObject msg = new JSONObject(); 
       msg.put("title", "Title"); 
       msg.put("body", "Body"); 
       JSONObject json = new JSONObject(); 
       json.put("data", msg); 
       HttpPut request = new HttpPut(furl); 

       request.setHeader("Content-type", MediaType.APPLICATION_JSON); 
       StringEntity params = new StringEntity(json.toString());   
       request.setEntity(params); 
HttpResponse response = httpClient.execute(request); 
       Integer responseCode = response.getStatusLine().getStatusCode(); 
       System.out.println(responseCode); 
      }catch(Exception e){ 
       e.printStackTrace(); 
      } 
     } 

私はこの1つを手伝ってもらえますか?

+0

、あなたのセットのヘッダーとエンティティのプロパティの前に、あなたの要求を実行しています。 – f1sh

+0

Sorry..its typo ..ヘッダーを設定した後でコードを実行しています。私はあなたが同じエラーを取得している:-(..私は..試みたが、働いていない – Thulasiram

答えて

0

私はあなたのコードにタイプミスがあると思う:あなたの2番目のコードスニペットでのContent T YPE

request.setHeader("Content-Type", MediaType.APPLICATION_JSON); 
+0

を更新しました?私は2番目のコードスニペットを使用していたときに – Thulasiram

+0

をコード – Vijay

+0

ません..私は400、ステータスコードを取得しています。.. – Thulasiram

関連する問題