服务器的代码如下: ServletInputStream inputStream = ((ServletRequest) request)
.getInputStream();
int len, offset, count;
count = offset = 0;
byte[] buffer = new byte[1024]; try {
FileOutputStream outputStream = new FileOutputStream("D:\\123.jpg");
while ((len = inputStream.readLine(buffer, 0, 1024)) != -1) {
offset += len;
outputStream.write(buffer, 0, len);
}
outputStream.flush();
outputStream.close();
} catch (Exception e) {
System.out.println(e.toString());
} PrintWriter out = response.getWriter();
out.println("ok");

解决方案 »

  1.   

    setRequestProperty主要是设置HttpURLConnection请求头里面的属性
    比如Cookie、User-Agent(浏览器类型)等等,具体可以看HTTP头相关的材料
    至于要设置什么这个要看服务器端的约定
      

  2.   

    设置头信息的,比如格式,UA等,不设置自然有默认的,一般的请求倒不需要去设置,可以去看看android里的DefaultHttpClient里也有设置头信息的
      

  3.   

    setRequestProperty 主要是用来设置下面的功能
    connection.setRequestProperty("Connection", "Keep-Alive");
    connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
    或者
    Connection.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
    有时候你需要给 connection 指定 Content-type。
     
      

  4.   

    可不可以把代码贴全啊,本人Android菜鸟,希望能多学习
      

  5.   

    HTTP sends such requests with a Content-Type: multipart/form-data header or a
    Content-Type: multipart/mixed header and a multipart body, like this:
    Content-Type: multipart/form-data; boundary=[abcdefghijklmnopqrstuvwxyz]
    where the boundary specifies the delimiter string between the different parts of the
    body.