hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtomy <mvtomi...@gmail.com>
Subject HttpClient gives HTTP 404 after multipart form submit
Date Wed, 04 Nov 2009 22:02:57 GMT

Hello.

I'm using HttpClient 4.0 in my project. Firstly i'm submitting multipart
form this way:

    HttpPost httpPost = new HttpPost("http://[host here]/in.php");

    MultipartEntity entity = new
MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    entity.addPart("method", new StringBody("post"));
    entity.addPart("key", new StringBody("223fwe0923fjf23"));
    FileBody fileBody = new FileBody(new File("photo.jpg"), "image/jpeg");
    entity.addPart("file", fileBody);
    httpPost.setEntity(entity);

    HttpResponse response = httpClient.execute(httpPost);       
    HttpEntity result = response.getEntity();

    String responseString = "";
    if (result != null) {
        InputStream inputStream = result.getContent();

        byte[] buffer = new byte[1024];
        while(inputStream.read(buffer) > 0)
            responseString += new String(buffer);

        result.consumeContent();
    }

This performs successfully.
Then I'm getting some status info about form i've just submitted. I do it
like this:

    HttpGet httpGet = new HttpGet("http://[host
here]/res.php?key="+myKey+"&action=get&id="+id);
    HttpResponse response = httpClient.execute(httpGet);
    HttpEntity entity = response.getEntity();

execute() method throws ClientProtocolException. Using log4j i knew that web
server says about HTTP 404 error.
Wierd detail: 
DEBUG [org.apache.http.wire] >> "GET
/res.php?key=46a350bd56f9&action=get&id=89619587[0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0]
....
Endless nulls in the end of request that are not concerned with my id
variable.

One more detail: if i comment lines where i use FileBody class, all works
fine with no any exceptions and HTTP 404. So, the problem isn't web server
problem.

Am I working with multipart form wrong way?  Any help appreciated.
Thank you.
-- 
View this message in context: http://old.nabble.com/HttpClient-gives-HTTP-404-after-multipart-form-submit-tp26204975p26204975.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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


Mime
View raw message