是否可以在同一httpurlconnection中发送java对象并上载文件?
我试着解释我想做什么。 只需在同一http连接中发送包含某些字段和任何类型文件的java对象。 我试了很多方法,但都不明白是否可以在同一httpurlconnection中发送java对象并上载文件?,java,httpurlconnection,Java,Httpurlconnection,我试着解释我想做什么。 只需在同一http连接中发送包含某些字段和任何类型文件的java对象。 我试了很多方法,但都不明白 // can be send only java object, can be send only file // but need to send both of them in same connection //imagine there is an object public ObjectWillBeSended request;
// can be send only java object, can be send only file
// but need to send both of them in same connection
//imagine there is an object
public ObjectWillBeSended request;
//imagine there is a file
File theFileWillBeUpload;
URL url = new URL(<url_path>);
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
// what will be header params ?
uc.setRequestMethod("POST");
uc.setRequestProperty("Accept", "<?>");
uc.setRequestProperty("Content-Type","<?>");
DataOutputStream dos = new DataOutputStream(uc.getOutputStream());
// What I do exactly there, open to any idea.
...
// Then sended object (request) and file (theFileWillBeUpload) in same HttpURLConnection ?
int responseCode = urlConnection.getResponseCode();
//只能是发送java对象,只能是发送文件
//但是需要在同一个连接中发送这两个
//想象有一个物体
公众反对将被撤销的请求;
//想象有一个文件
文件将被上传;
URL=新URL();
HttpURLConnection uc=(HttpURLConnection)url.openConnection();
//标题参数是什么?
uc.setRequestMethod(“POST”);
uc.setRequestProperty(“接受”、“接受”);
uc.setRequestProperty(“内容类型”和“”);
DataOutputStream dos=新的DataOutputStream(uc.getOutputStream());
//我在那里做什么,什么都可以。
...
//然后在同一httpurl连接中发送对象(请求)和文件(文件将被上传)?
int responseCode=urlConnection.getResponseCode();