Skip to content

Commit 6da235c

Browse files
authored
Merge pull request #102 from aahill/master
Adding code tags, and fixing Post request
2 parents 2476e75 + f6a855a commit 6da235c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

java/InkRecognition/quickstart/RecognizeInk.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3-
3+
// <imports>
44
import org.apache.http.HttpEntity;
55
import org.apache.http.client.methods.CloseableHttpResponse;
6-
import org.apache.http.client.methods.HttpPost;
6+
import org.apache.http.client.methods.HttpPut;
77
import org.apache.http.entity.StringEntity;
88
import org.apache.http.impl.client.CloseableHttpClient;
99
import org.apache.http.impl.client.HttpClients;
1010
import org.apache.http.util.EntityUtils;
1111
import java.io.IOException;
1212
import java.nio.file.Files;
1313
import java.nio.file.Paths;
14+
// </imports>
1415

1516
public class RecognizeInk {
16-
17+
// <vars>
1718
// Add your Azure Ink Recognition subscription key to your environment variables.
1819
private static final String subscriptionKey = System.getenv("INK_RECOGNITION_SUBSCRIPTION_KEY");
1920

@@ -22,23 +23,26 @@ public class RecognizeInk {
2223
public static final String inkRecognitionUrl = "/inkrecognizer/v1.0-preview/recognize";
2324
// Replace the dataPath string with a path to the JSON formatted ink stroke data file.
2425
private static final String dataPath = "PATH_TO_INK_STROKE_DATA";
25-
26+
// </vars>
27+
// <main>
2628
public static void main(String[] args) throws Exception {
2729

2830
String requestData = new String(Files.readAllBytes(Paths.get(dataPath)), "utf-8");
2931
recognizeInk(requestData);
3032
}
31-
33+
// </main>
34+
// <recognizeInk>
3235
static void recognizeInk(String requestData) {
3336
System.out.println("Sending an Ink recognition request.");
3437

3538
String result = sendRequest(rootUrl, inkRecognitionUrl, subscriptionKey, requestData);
3639
System.out.println(result);
3740
}
38-
41+
// </recognizeInk>
42+
// <sendRequest>
3943
static String sendRequest(String endpoint, String apiAddress, String subscriptionKey, String requestData) {
4044
try (CloseableHttpClient client = HttpClients.createDefault()) {
41-
HttpPost request = new HttpPost(endpoint + apiAddress);
45+
HttpPut request = new HttpPut(endpoint + apiAddress);
4246
// Request headers.
4347
request.setHeader("Content-Type", "application/json");
4448
request.setHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
@@ -57,4 +61,5 @@ static String sendRequest(String endpoint, String apiAddress, String subscriptio
5761
}
5862
return null;
5963
}
64+
// </sendRequest>
6065
}

0 commit comments

Comments
 (0)