0

我需要使用 httppost 类型将文件上传到服务器。在服务器端,他们收到了 httppostedfilebase 实例中的文件。

这个怎么做?建议我。

4

1 回答 1

0

尝试这个:

url = new URL("http://....");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
outputStream = new DataOutputStream( connection.getOutputStream() );
outputStream.writeBytes(stufftosend);
outputStream.flush();
outputStream.close();  
于 2013-07-10T10:07:33.840 回答