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

  • Home
  • SEARCH
  • 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 6909609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:42:40+00:00 2026-05-27T08:42:40+00:00

I am making a HTTP POST query to a server and I am creating

  • 0

I am making a HTTP POST query to a server and I am creating the post body manually.
I think I am making some mistake with the content-length header because on the server side when I get the http response at the beginning I see the headers with http response 200 and then when in my php script I print the post parameters and file names I get the correct values but together with some junk bytes.
Here is the body of my http post:

StringBuffer str = new StringBuffer();
str.append("POST /tst/query.php HTTP/1.1\r\n"
        + "Host: myhost.com\r\n"
        + "User-Agent: sampleAgent\r\n"
        + "Content-type: multipart/form-data, boundary=AaB03x\r\n" 
        + "Content-Length: 172\r\n\r\n"
        + "--AaB03x\r\n"
        + "content-disposition: form-data; name=\"asd\"\r\n\r\n123\r\n--AaB03x\r\n"
        + "content-disposition: form-data; name=\"pics\"; filename=\"file1.txt\"\r\n"
        + "Content-Type: text/plain\r\n\r\n555\r\n"
        + "--AaB03x--"
);

Here is the output from the server(ignore [0.0] – it comes from the console where I print the result)

[0.0] HTTP/1.1 200 OK

[0.0] Date: Sat, 10 Dec 2011 11:53:11 GMT

[0.0] Server: Apache

[0.0] Transfer-Encoding: chunked

[0.0] Content-Type: text/html

[0.0] 

[0.0] 6

[0.0] Array
[0.0] 

[0.0] 2

[0.0] (
[0.0] 

[0.0] 1

[0.0]  

[0.0] 1

[0.0]  

[0.0] 1

[0.0]  

[0.0] 1

[0.0]  

[0.0] 1

[0.0] [

[0.0] 3

[0.0] asd

[0.0] 5

[0.0] ] => 

3
123
1
2
)
0

And the php script on the server which is as simple as you can think of:

<?php 
    print_r($_POST) ;
?>
  • 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-27T08:42:41+00:00Added an answer on May 27, 2026 at 8:42 am
    String boundary = "AaB03x";
    String body = "--" + boundary + "\r\n"
                + "Content-Disposition: form-data; name=\"asd\"\r\n"
                + "\r\n"
                + "123\r\n"
                + "--" + boundary + "\r\n"
                + "Content-Disposition: form-data; name=\"pics\"; filename=\"file1.txt\"\r\n"
                + "Content-Type: text/plain\r\n"
                + "\r\n"
                + "555\r\n"
                + "--" + boundary + "--";
    
    StringBuffer str = new StringBuffer();
    str.append("POST /tst/query.php HTTP/1.1\r\n"
             + "Host: myhost.com\r\n"
             + "User-Agent: sampleAgent\r\n"
             + "Content-type: multipart/form-data, boundary=\"" + boundary + "\"\r\n" 
             + "Content-Length: " + body.length() + "\r\n"
             + "\r\n"
             + body
    );
    

    …I would say is the way it should be done

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

Sidebar

Related Questions

I am making HTTP connections to server to get some data. It works on
Just want to verify, when making a SSL connection (http post) to say: https://www.example.com/some/path?customer_key=123123123
Debugging experience http://www.dmhermitage.org/wtfborders.png This is making me want to kill myself. I have some
I'm making the following request through command-line cURL: curl -X POST http://localhost:8000/api/places/ -vvvv -d
I'm making an HTTP POST request using curl like this: curl -v -i -d
I'm working on making an HTTP server for my class. But, the returned file
I'm making simple http post request using libcurl to index.php file on my web
I stumbled upon some code the other day that was making use of query
I'm making a HTTP Post and I would like to know how to convert
I am making a HTTP POST request from GWT Client to a HTTPServlet. This

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.