Java Reference
In-Depth Information
}
static void doGet(String isbn) throws Exception
{
URL url = new URL(LIBURI+((isbn != null) ? "?isb-
n="+isbn : ""));
HttpURLConnection
httpurlc
=
(HttpURLConnection)
url.openConnection();
httpurlc.setRequestMethod("GET");
httpurlc.setDoInput(true);
InputStreamReader isr;
isr
=
new
InputStreamRead-
er(httpurlc.getInputStream());
BufferedReader br = new BufferedReader(isr);
StringBuilder xml = new StringBuilder();
String line;
while ((line = br.readLine()) != null)
xml.append(line);
System.out.println(xml);
System.out.println();
}
static void doPost(String xml) throws Exception
{
URL url = new URL(LIBURI);
HttpURLConnection
httpurlc
=
(HttpURLConnection)
url.openConnection();
httpurlc.setRequestMethod("post");
httpurlc.setDoOutput(true);
httpurlc.setDoInput(true);
httpurlc.setRequestProperty("content-type",
"text/
xml");
OutputStream os = httpurlc.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os,
"utf-8");
osw.write(xml);
osw.close();
if (httpurlc.getResponseCode() == 200)
Search WWH ::




Custom Search