This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Making URLConnection through servlet
Posted by Gerhard Kreutzer on November 21, 2001 at 7:57 AM
> Hi!, > How do i make URL connection in servlet? IF anyone has running code please pass it on. > What factures we need to take into account in such a case for CONNECTION POOLING!! > > Thanks > Gouri hi gouri, try it this way: URL url = new URL(); String strInEnc = URLEncoder.encode("inp") + "=" + URLEncoder.encode(); URLConnection uc = url.openConnection(); uc.setDoOutput(true); uc.setDoInput(true); uc.setUseCaches(false); uc.setRequestProperty("Content-type", "application/x-www-form-urlencoded"); DataOutputStream dos = new DataOutputStream(uc.getOutputStream()); dos.writeBytes(strInEnc); dos.flush(); dos.close(); InputStreamReader in = new InputStreamReader(uc.getInputStream()); int chr = in.read(); while (chr != -1) { taResults.append(String.valueOf((char) chr)); chr = in.read(); } in.close();
Replies:
|