URLConnection 建立 网络传输限长?

ndzj981479673 2011-02-22 07:55:18
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个字符,难道是我写错了,求指点。。。
...全文
76 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ndzj981479673 2011-05-25
  • 打赏
  • 举报
回复
额,什么格式的都不行的说,果断放弃字符串传输,选择传类得了~
penghaiwudi 2011-02-23
  • 打赏
  • 举报
回复
传多了会出现什么情况? 提示什么 比如你传个大文件会报错?
你传个其他格式的大文件试试

50,527

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧