views:

290

answers:

1

I'm uploading a multipart chunk of data using HttpPost and feeding it into an HttpClient objects execute method as follows:

HttpPost loginPost = new HttpPost(LOGIN_URL);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("_email", mEmailAddress));
params.add(new BasicNameValuePair("lpassword", mPassword));

UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");

loginPost.setEntity(entity);
HttpResponse resp = mHttpClient.execute(loginPost);

HttpPost post = new HttpPost(UPLOAD_URL);
FileBody bin = new FileBody(file);
MultipartEntity me = new MultipartEntity();

me.addPart("stuff", new StringBody(stuff));
me.addPart("file", bin);

post.setEntity(new RequestEntityEx(me, handler));
mHttpClient.execute(post);

Now, logging in and posting work - fine but uploading is painfully slow. I've tested my internet connection and it's far slower than what it should be (approx. up speed is 1Mb/s, uploading a 3MB file is taking around 5 minutes (rather than 30s).

Anyone have any ideas?

A: 

I've found that HttpClient is like 9 times slower than regular way on https. I have no idea why, anybody knows what's wrong.

Here is basically my code

private static HttpClient httpClient = new DefaultHttpClient();
private static HttpPost httpPost = new HttpPost(RRD_URL);

    public static String sendData(List<NameValuePair> data) {
    StringBuffer buffer = new StringBuffer();
    BufferedReader rd = null;
    try {
        httpPost.setEntity(new UrlEncodedFormEntity(data));
        HttpResponse httpResponse = httpClient.execute(httpPost);

        rd = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
        String line;
        while ((line = rd.readLine()) != null) {
            buffer.append(line);
        }
    } catch (IOException e) {
        e.printStackTrace(System.out);
    } finally {
        try {
            if (rd != null) {
                rd.close();
            }
        } catch (IOException e) {
            e.printStackTrace(System.out);
        }
    }

    return buffer.toString();
}
Alex Givant
This should be posted as a separate question, not as an answer. See the **[Ask Question]** button at the top right of the page.
Bill the Lizard