質問編集履歴
1
PSを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,3 +9,101 @@
|
|
9
9
|
(国外も探したのですが、JAVAで認識しない型のクラス変数などを(DefaultHttpClient)
|
10
10
|
|
11
11
|
使っており、流用できないのです)
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
PS.サンプルソースがありました。
|
18
|
+
|
19
|
+
ただ、DefaultHttpClient、HttpClientParams、JSONObjectなどなど、
|
20
|
+
|
21
|
+
ecilpsで、自動宣言してくれるものがなく、これらがエラーになって困っています。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
try {
|
28
|
+
|
29
|
+
String url = "https://buy.itunes.apple.com/verifyReceipt";
|
30
|
+
|
31
|
+
DefaultHttpClient client = null;
|
32
|
+
|
33
|
+
try {
|
34
|
+
|
35
|
+
String input = IOUtils.toString(is);
|
36
|
+
|
37
|
+
log.info("THE INPUTSTREAM: " + input);
|
38
|
+
|
39
|
+
JSONObject receipt = new JSONObject();
|
40
|
+
|
41
|
+
receipt.put("receipt-data", input);
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
client = new DefaultHttpClient();
|
46
|
+
|
47
|
+
HttpPost post = new HttpPost(url);
|
48
|
+
|
49
|
+
StringEntity entity = new StringEntity(receipt.toString());
|
50
|
+
|
51
|
+
entity.setContentType("application/json");
|
52
|
+
|
53
|
+
post.setEntity(entity);
|
54
|
+
|
55
|
+
HttpClientParams.setRedirecting(post.getParams(), false);
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
HttpResponse response = client.execute(post);
|
60
|
+
|
61
|
+
if (300 <= response.getStatusLine().getStatusCode()) {
|
62
|
+
|
63
|
+
throw new RuntimeException("No response from iTune store. status code: " + response.getStatusLine().getStatusCode());
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
if (null == response.getEntity()) {
|
70
|
+
|
71
|
+
log.info("Response is null");
|
72
|
+
|
73
|
+
throw new Exception("Response is null");
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
StringBuilder sb = new StringBuilder();
|
80
|
+
|
81
|
+
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
82
|
+
|
83
|
+
for (String line; null != (line = reader.readLine());) {
|
84
|
+
|
85
|
+
sb.append(line);
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
JSONObject json = new JSONObject(sb.toString());
|
90
|
+
|
91
|
+
log.info("THE JSON" + json);
|
92
|
+
|
93
|
+
//Then work with json below
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
} catch (Exception e) {
|
98
|
+
|
99
|
+
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build());
|
100
|
+
|
101
|
+
} finally {
|
102
|
+
|
103
|
+
if (null != client) {
|
104
|
+
|
105
|
+
client.getConnectionManager().shutdown();
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
}
|