質問するログイン新規登録

質問編集履歴

1

PSを追加

2015/10/23 07:54

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -3,4 +3,53 @@
3
3
  どこかにサンプルなどありまでしょうか?
4
4
 
5
5
  (国外も探したのですが、JAVAで認識しない型のクラス変数などを(DefaultHttpClient)
6
- 使っており、流用できないのです)
6
+ 使っており、流用できないのです)
7
+
8
+
9
+ PS.サンプルソースがありました。
10
+ ただ、DefaultHttpClient、HttpClientParams、JSONObjectなどなど、
11
+ ecilpsで、自動宣言してくれるものがなく、これらがエラーになって困っています。
12
+
13
+
14
+ try {
15
+ String url = "https://buy.itunes.apple.com/verifyReceipt";
16
+ DefaultHttpClient client = null;
17
+ try {
18
+ String input = IOUtils.toString(is);
19
+ log.info("THE INPUTSTREAM: " + input);
20
+ JSONObject receipt = new JSONObject();
21
+ receipt.put("receipt-data", input);
22
+
23
+ client = new DefaultHttpClient();
24
+ HttpPost post = new HttpPost(url);
25
+ StringEntity entity = new StringEntity(receipt.toString());
26
+ entity.setContentType("application/json");
27
+ post.setEntity(entity);
28
+ HttpClientParams.setRedirecting(post.getParams(), false);
29
+
30
+ HttpResponse response = client.execute(post);
31
+ if (300 <= response.getStatusLine().getStatusCode()) {
32
+ throw new RuntimeException("No response from iTune store. status code: " + response.getStatusLine().getStatusCode());
33
+ }
34
+
35
+ if (null == response.getEntity()) {
36
+ log.info("Response is null");
37
+ throw new Exception("Response is null");
38
+ }
39
+
40
+ StringBuilder sb = new StringBuilder();
41
+ BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
42
+ for (String line; null != (line = reader.readLine());) {
43
+ sb.append(line);
44
+ }
45
+ JSONObject json = new JSONObject(sb.toString());
46
+ log.info("THE JSON" + json);
47
+ //Then work with json below
48
+
49
+ } catch (Exception e) {
50
+ throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build());
51
+ } finally {
52
+ if (null != client) {
53
+ client.getConnectionManager().shutdown();
54
+ }
55
+ }