Skip to content

Commit 41881a2

Browse files
author
aribornstein
committed
adding code
1 parent 5b56c86 commit 41881a2

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

src/JavaAzureMLClient.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import java.net.*;
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class AzureMLClient
6+
{
7+
8+
private endPointURL; //Azure ML Endpoint
9+
private key; //API KEY
10+
11+
12+
public AzureMLClient(String endPointURL,String key)
13+
{
14+
this.endPointURL= endPointURL;
15+
this.key= key;
16+
}
17+
/*
18+
Takes an Azure ML Request Body then Returns the Response String Which Contains Scored Lables etc
19+
*/
20+
public static String RequestResponse( String requestBody ) throws Exception
21+
{
22+
URL u = new URL(this.endPointURL);
23+
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
24+
25+
conn.setRequestProperty("Authorization","Bearer "+ this.key);
26+
conn.setRequestProperty("Content-Type","application/json");
27+
28+
conn.setRequestMethod("POST");
29+
String body= new String(requestBody);
30+
31+
conn.setDoOutput(true);
32+
OutputStreamWriter wr=new OutputStreamWriter(conn.getOutputStream());
33+
34+
wr.write(body);
35+
wr.close();
36+
37+
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
38+
39+
String decodedString;
40+
String responseString="";
41+
42+
while ((decodedString = in.readLine()) != null)
43+
{
44+
response+=decodedString;
45+
}
46+
return responseString;
47+
}
48+
49+
}

0 commit comments

Comments
 (0)