whp320
发贴: 3
|
于 2006-03-16 14:28
java.net.UnknownServiceException: protocol doesn't support output at java.net.URLConnection.getOutputStream(Unknown Source)
程序代码如下: URL servletURL=new URL(this.getDocumentBase(),"queryServlet"); URLConnection connection=servletURL.openConnection(); // System.out.println(connection.getAllowUserInteraction()); System.out.print(connection.getAllowUserInteraction()); connection.setUseCaches(false); connection.setDoOutput(true); ByteArrayOutputStream byteStream=new ByteArrayOutputStream(1024); PrintWriter outf=new PrintWriter(byteStream,true); String postData="timeStr="+URLEncoder.encode(timeStr); postData+="Airtimes="+URLEncoder.encode(Airtimes); outf.print(postData); outf.flush(); String lengthString=String.valueOf(byteStream.size()); connection.setRequestProperty("Content-length",lengthString); connection.setRequestProperty("Content-Type","application/x-www-form-rulencoded"); //这句报的错误!!! byteStream.writeTo(connection.getOutputStream()); BufferedReader br=new BufferedReader(new InputStreamReader(connection.getInputStream())); String resultStr=br.readLine();
|