15 package com.trouch.webiopi.client;
17 import java.io.BufferedReader;
18 import java.io.IOException;
19 import java.io.InputStreamReader;
20 import java.net.HttpURLConnection;
27 super(
"http", host, DEFAULT_PORT);
31 super(
"http", host, port);
35 public String
sendRequest(String method, String path)
throws Exception {
36 BufferedReader reader = null;
39 HttpURLConnection connection = (HttpURLConnection) url.openConnection();
40 connection.setRequestMethod(method);
41 if (this.
auth != null) {
42 connection.setRequestProperty(
"Authorization", this.
auth);
46 reader =
new BufferedReader(
new InputStreamReader(connection.getInputStream()));
47 StringBuilder stringBuilder =
new StringBuilder();
50 while ((line = reader.readLine()) != null) {
51 stringBuilder.append(line).append(
'\n');
53 return stringBuilder.toString();
54 }
catch (Exception e) {
61 }
catch (IOException ioe) {
62 ioe.printStackTrace();
static final int DEFAULT_PORT
PiHttpClient(String host)
PiHttpClient(String host, int port)
String sendRequest(String method, String path)