URLConnection 建立 网络传输限长?
cs模式,客户向服务器提交请求,服务器响应请求(返回一串字符流)
但是感觉最多只能传送16000个字符,难道真的限长???
求指点!!!
代码
客户端:
java.net.URL url;
try {
url = new java.net.URL("http://localhost:8080/servlet/HelloWorldExample");//
java.net.URLConnection con;
InputStream in = null;
DataInputStream inn = null;
try {
con = url.openConnection();
con.setUseCaches(false);
con.setDoOutput(true);
con.setDoInput(true);
//缓存
try
{
StringBuffer function = new StringBuffer("barcode 211111 true 2");//"a "+Type+" "+bb+" "+top
StringBuffer stringbuffer = function; //Attention!!!
//发送
DataOutputStream dataOut = new DataOutputStream(con.getOutputStream());
dataOut.writeUTF(stringbuffer.toString());//
dataOut.flush();
dataOut.close();
//获取服务器端返回信息
in = con.getInputStream();
byte[]b = new byte[in.available()];
in.read(b);
String s =new String(b,"UTF-8");
String filename2 = "e:\\a.txt";
File f = new File(filename2);//"E:\\out.xml"
OutputStream p = new FileOutputStream(f);
p.write(b);
p.close();
}
finally
{
try
{
if(in!=null)
in.close();
}
catch(EOFException e2)
{
System.out.println(e2);
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
服务器:
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
response.setContentType("text/html;charset=utf-8");
String filename = null;
DataInputStream in = new DataInputStream(request.getInputStream());//,"UTF-8"
OutputStream os = response.getOutputStream();
String stringValue = in.readUTF();
filename = "e://b.txt";
InputStream is = new FileInputStream(filename);//
byte []b= new byte[is.available()];
is.read(b);//,0,is.available()
is.close();
os.write(b);
os.flush();
os.close();
}
我以为没有长度限制的,可是偏偏它就只能传16000个字符,难道是我写错了,求指点。。。