質問編集履歴

1

ソースの編集

2017/06/24 16:56

投稿

qazwsx_15
qazwsx_15

スコア10

test CHANGED
File without changes
test CHANGED
@@ -28,12 +28,78 @@
28
28
 
29
29
  ```
30
30
 
31
+ ```Java
32
+
33
+ @Override
34
+
35
+ protected void onCreate(Bundle savedInstanceState) {
36
+
37
+ super.onCreate(savedInstanceState);
38
+
39
+ setContentView(R.layout.activity_main);
40
+
41
+
42
+
43
+ // 1. HTTPクライアントを生成
44
+
45
+ //ここでエラーが出る
46
+
47
+ try (CloseableHttpClient client = HttpClients.createDefault()) {
48
+
49
+
50
+
51
+ // 2. POST要求を生成
52
+
53
+ // 分析対象の画像のURLを指定するJSON文字列
54
+
55
+ String req = "{ \"url\": \"https://portalstoragewuprod.azureedge.net/media/Default/Media/EmotionAPI/Emotion.jpg\" }";
56
+
57
+ // POSTメソッドを生成
58
+
59
+ HttpPost post = new HttpPost("EMOTION_API_URL");
60
+
61
+ post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
62
+
63
+ post.setHeader("Ocp-Apim-Subscription-Key", "SUBSCRIPTION");
64
+
65
+ post.setEntity(new StringEntity(req));
66
+
67
+
68
+
69
+ // 3. APIを呼び出し応答データを取得
70
+
71
+ try (CloseableHttpResponse response = client.execute(post)) {
72
+
73
+ String resp = EntityUtils.toString(response.getEntity());
74
+
75
+ System.out.println(resp);
76
+
77
+ }
78
+
79
+ } catch (IOException e) {
80
+
81
+ e.printStackTrace();
82
+
83
+ }
84
+
85
+ }
86
+
87
+ }
88
+
89
+ ```
90
+
91
+
92
+
93
+
94
+
31
95
 
32
96
 
33
97
  ###補足情報(言語/FW/ツール等のバージョンなど)
34
98
 
35
99
  言語はJava、AndroidStudio2.3.3、compileSdkVersion 25、buildToolsVersion "25.0.3"です。
36
100
 
101
+ 利用ライブラリはHttpClient 4.5.3 (GA)です。
102
+
37
103
 
38
104
 
39
105
  このエラーの原因は何なのでしょうか。また、どのように書き換えれば解決できるのでしょうか。教えていただきたいです。