Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1113221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:49:29+00:00 2026-05-17T02:49:29+00:00

Java Code: HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( http://localhost/SC/upload.php); FileBody

  • 0

Java Code:

            HttpClient httpclient = new DefaultHttpClient();

        HttpPost httppost = new HttpPost(
                "http://localhost/SC/upload.php");

        FileBody bin = new FileBody(f3);

        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("bin", bin);

        httppost.setEntity(reqEntity);

        System.out
                .println("executing request " + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (resEntity != null) {
            System.out.println("Response content length: "
                    + resEntity.getContentLength());
            System.out.println("Chunked?: " + resEntity.isChunked());
            System.out.println("Response: "
                    + EntityUtils.toString(resEntity));
        }
        if (resEntity != null) {
            resEntity.consumeContent();
        }

PHP Code:

    <?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }

print_r ($_FILES);
?> 

Every time I run the Java Code, I always get:

executing request POST http://localhost/SC/upload.php HTTP/1.1
—————————————-
HTTP/1.1 200 OK
Response content length: 241
Chunked?: false
Response: Upload:
Type:
Size: 0 Kb
Stored in: Array
(
[bin] => Array
(
[name] => File.tar.lzma
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)

)

I’ve tested it with normal http upload (through webbrowser, same file) and it works.

What am I doing wrong?

EDIT: f3 is a File (that I KNOW exists, (/home/me/Desktop/File.tar.lzma))

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:49:30+00:00Added an answer on May 17, 2026 at 2:49 am

    It turns out that it really WAS a php max file size problem, although it under the limit (2M), I didn’t know that the java code was adding parts to the file (in the TAR code)

    Increasing the limit fixed the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my .java HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(http://*******.com/mobileproject/updateclass.php);
Here's my code: HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(http://www.webcitation.org/comb.php); try
i write this code in main.java ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); try{ HttpClient httpclient
So I've got some Java code that uses Jakarta HttpClient like this: URI aURI
I'm using the following java code to upload a multi-part image to an ASMX
Probably problem with the php file which contains the following code: <?php mysql_connect(localhost,root,); mysql_select_db(deal);
This Java code compiles fine, but when I try to run it I get:
Will Java code built and compiled against a 32-bit JDK into 32-bit byte code
IN JAVA CODE IN JSP as below i m getting null value for fieldnoOfRecords.
My Java code must get string HH:MM from console and needs to operate with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.