File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments