You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Bastian Tweddell <gr...@nurfuerspam.de> on 2005/12/09 14:59:56 UTC

How to use PostMethod with a MultiPartRequest?

I dont know how to upload a file with the PostMethod (btw uploading files
with the PutMethod worked great, but i need to upload large files)

I have read the whole day and didnt find anything that could help me. The 
code i have so far should upload the local file 'local=/home/my/file.a' to
the url 'http://loclahost:8080/username/file.b' (because different names
should be possible)


PostMethod method2 = null;
try {
	System.out.println();
	method2 = new PostMethod(url + "/" + remote);
	Part[] parts = {
		new FilePart(local.getName(), local)
	};
	method2.setRequestEntity(
		new MultipartRequestEntity(parts, method2.getParams())
	);
} catch (FileNotFoundException e) {
	log.warning("File doesnt exist: " + local);
	e.printStackTrace();
	return false;
}
try {
	// Execute the
method.
	httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
int statusCode = httpclient.executeMethod(method2);
if (statusCode != HttpStatus.SC_OK) {
	log.warning("PostMethod failed: " + method2.getStatusLine() + "
Statuscode="+statusCode);
			} else {
.
.
.



But this doesnt work. And i really Dont know if this is a client or server
side problem. As server i use jetty, but jetty is capable of handling
multipart/form. On the serverside i only added a HttpContext.


Thx for any help
Bastian




-- 
Telefonieren Sie schon oder sparen Sie noch?
NEU: GMX Phone_Flat http://www.gmx.net/de/go/telefonie

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: How to use PostMethod with a MultiPartRequest?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2005-12-09 at 14:59 +0100, Bastian Tweddell wrote:
> I dont know how to upload a file with the PostMethod (btw uploading files
> with the PutMethod worked great, but i need to upload large files)
> 
> I have read the whole day and didnt find anything that could help me. The 
> code i have so far should upload the local file 'local=/home/my/file.a' to
> the url 'http://loclahost:8080/username/file.b' (because different names
> should be possible)
> 
> 
> PostMethod method2 = null;
> try {
> 	System.out.println();
> 	method2 = new PostMethod(url + "/" + remote);
> 	Part[] parts = {
> 		new FilePart(local.getName(), local)
> 	};
> 	method2.setRequestEntity(
> 		new MultipartRequestEntity(parts, method2.getParams())
> 	);
> } catch (FileNotFoundException e) {
> 	log.warning("File doesnt exist: " + local);
> 	e.printStackTrace();
> 	return false;
> }
> try {
> 	// Execute the
> method.
> 	httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
> int statusCode = httpclient.executeMethod(method2);
> if (statusCode != HttpStatus.SC_OK) {
> 	log.warning("PostMethod failed: " + method2.getStatusLine() + "
> Statuscode="+statusCode);
> 			} else {
> .
> .
> .

> But this doesnt work. And i really Dont know if this is a client or server
> side problem. 

Bastian,

You can monitor what gets sent and received across the wire by
activating the wire logging. For details see the HttpClient logging
guide

http://jakarta.apache.org/commons/httpclient/logging.html

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org