客户端:
sc = (HttpConnection)Connector.open( url, Connector.READ_WRITE, true );
sc.setRequestMethod( HttpConnection.POST );
sc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
sc.setRequestProperty("Content-Length", String.valueOf(data.length));
OutputStream output = sc.openOutputStream();
output.write(data, 0, data.length);
output.flush();
output.close();
服务器端:
java.io.InputStream in = request.getInputStream();
byte[] b = new byte[100000];
byte[] tmp = new byte[100000];
int size = 0;
java.io.File f = new java.io.File( request.getRealPath("/"), System.currentTimeMillis() + ".png");
java.io.DataOutputStream o = new java.io.DataOutputStream(new java.io.FileOutputStream(f));
int len = 0;
while( ( len = in.read( tmp ) ) != -1 )
{
o.write(tmp,0,len);
size+=len;
}
o.close();
1.我的程序在模拟器上上传图片,服务器可以接收到;而使用真机(索爱k700和k750c)上传,则服务器收到的是0字节,此时查看手机流量,确实已经把10k的数据发出去了,请问这是什么原因?
--------------------------------------------------------------------------------
1.先确定你的SIM卡是CMWAP还是CMNET,CMWAP连接网络的时候需要做代理;
--------------------------------------------------------------------------------
应该是你的HTTP头设置问题
sc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
改为
sc.setRequestProperty("Content-Type", "application/octet-stream");
--------------------------------------------------------------------------------
多谢大侠指点,问题解决了,真是一语道破个中玄机,的确是HTTP头的设置问题.