-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJavaAzureMLClient.java
More file actions
49 lines (37 loc) · 1.32 KB
/
JavaAzureMLClient.java
File metadata and controls
49 lines (37 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.net.*;
import java.io.*;
import java.util.*;
public class AzureMLClient
{
private endPointURL; //Azure ML Endpoint
private key; //API KEY
public AzureMLClient(String endPointURL,String key)
{
this.endPointURL= endPointURL;
this.key= key;
}
/*
Takes an Azure ML Request Body then Returns the Response String Which Contains Scored Lables etc
*/
public static String requestResponse( String requestBody ) throws Exception
{
URL u = new URL(this.endPointURL);
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.setRequestProperty("Authorization","Bearer "+ this.key);
conn.setRequestProperty("Content-Type","application/json");
conn.setRequestMethod("POST");
String body= new String(requestBody);
conn.setDoOutput(true);
OutputStreamWriter wr=new OutputStreamWriter(conn.getOutputStream());
wr.write(body);
wr.close();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String decodedString;
String responseString="";
while ((decodedString = in.readLine()) != null)
{
response+=decodedString;
}
return responseString;
}
}