2012-01-03 9 views
2

私はJavaバックエンドを使用しています。ユーザーがアプリ内購入を行った後、フロントエンドは領収書を送信します。順番に、私は確認のためにリンゴに領収書を送ることです。リンゴは領収書をデコードし、私にJSON辞書を送り返します。私の質問は、私がjsonの応答を得ることができるようにリンゴに領収書を送り返すことです。私は以下のコードを使用しています。しかし、私はアップルから{"ステータス":21002}を得て、 "無効なCookieヘッダー"について何かを得ています。任意のアイデアをどのようにこれを解決するには?Javaを使用したアプリ内リンゴの受け取り

String url = "https://buy.itunes.apple.com/verifyReceipt"; 
    DefaultHttpClient client = null; 
    try { 
     String input = IOUtils.toString(is); 
     log.info("THE INPUTSTREAM: " + input); 
     JSONObject receipt = new JSONObject(); 
     receipt.put("receipt-data", input); 

     client = new DefaultHttpClient(); 
     HttpPost post = new HttpPost(url); 
     StringEntity entity = new StringEntity(receipt.toString()); 
     entity.setContentType("application/json"); 
     post.setEntity(entity); 
     HttpClientParams.setRedirecting(post.getParams(), false); 

     HttpResponse response = client.execute(post); 
     if (300 <= response.getStatusLine().getStatusCode()) { 
      throw new RuntimeException("No response from iTune store. status code: " + response.getStatusLine().getStatusCode()); 
     } 

     if (null == response.getEntity()) { 
      log.info("Response is null"); 
      throw new Exception("Response is null"); 
     } 

     StringBuilder sb = new StringBuilder(); 
     BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 
     for (String line; null != (line = reader.readLine());) { 
      sb.append(line); 
     } 
     JSONObject json = new JSONObject(sb.toString()); 
     log.info("THE JSON" + json); 
//Then work with json below 

    } catch (Exception e) { 
     throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build()); 
    } finally { 
     if (null != client) { 
      client.getConnectionManager().shutdown(); 
     } 
    } 

答えて

0

クッキーは必要ありませんか?試してみてください

HttpClientParams.setCookiePolicy(client.getParams(), CookiePolicy.IGNORE_COOKIES); 
関連する問題