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 7740647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:50:01+00:00 2026-06-01T08:50:01+00:00

I always get back Content Length Required 411, what am I doing wrong here?

  • 0

I always get back Content Length Required 411, what am I doing wrong here? am I not sending it right? Im sending to a RoR server. It basically will switch between statements depending on weather there is an image present or not. Thanks guys.

    public static void executeMultipartPost(Bitmap image, String topicid, String topost, Context c) throws Exception {
            String boundary = "------WebKitFormBoundary4QuqLuM1cE5lMwCy";

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            image.compress(CompressFormat.JPEG, 45, bos);
            byte[] data = bos.toByteArray();
            try
            {

                URL post_url = new URL("https://myapi");
                HttpURLConnection feed_connection = (HttpURLConnection) post_url.openConnection();
                feed_connection.setChunkedStreamingMode(0);
                feed_connection.setDoOutput(true);//make a POST Method as defualt is GET
                feed_connection.setRequestMethod("POST");
                feed_connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);


                //Now the actual composing of the multi part form
                String session_key = new String("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"session_key\"\r\n\r\n" + key + "\r\n");
                String feed = new String("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"feed\"\r\n\r\n" + topost + "\r\n");
                String sh_career = new String("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"share_to_career_team\"\r\n\r\n" + 0 + "\r\n");
                String sh_friend = new String("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"share_to_friend\"\r\n\r\n" + 0 + "\r\n");
                String url_t = new String("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"url_title\"\r\n\r\n"+"\r\n");
                String url_d = new String("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"url_description\"\r\n\r\n"+"\r\n");
                String url_a = new String("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"url_address\"\r\n\r\n"+"\r\n");
                String topic_id = new String("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"post_to\"\r\n\r\n" + topicid + "\r\n");


                if (data != null) {
                    String file_param_constant = "image";
                    Log.d("TAG","Image is here");
                    String image_part_1 = new String("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"richmedia_type\"\r\n\r\n" + "1\r\n");
                    String image_part_2 = new String("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"" + file_param_constant + "\"; filename=\"image.jpg\"\r\n" + "Content-Type: image/jpeg\r\n\r\n");
                    String missing_link = new String ("\r\n");
                    String image_part_3 = new String("--" + boundary + "--\r\n");
                    feed_connection.setRequestProperty("Content-Length", String.valueOf((session_key.length() + feed.length() + sh_career.length() + sh_friend.length() + url_t.length() + url_d.length() + url_a.length() + topic_id.length() + image_part_1.length() + image_part_2.length() + missing_link.length() + image_part_3.length())));
                    Log.d("TAG", "CONTENT LEGNTH WITH IMG:"+String.valueOf((session_key.length() + feed.length() + sh_career.length() + sh_friend.length() + url_t.length() + url_d.length() + url_a.length() + image.getByteCount() + topic_id.length())));
                    ByteArrayOutputStream form_output   = new ByteArrayOutputStream();
                    OutputStream form_stream            = new BufferedOutputStream(feed_connection.getOutputStream());
                    form_output.write(session_key.getBytes());
                    form_output.write(feed.getBytes());
                    form_output.write(sh_career.getBytes());
                    form_output.write(sh_friend.getBytes());
                    form_output.write(url_t.getBytes());
                    form_output.write(url_d.getBytes());
                    form_output.write(url_a.getBytes());
                    form_output.write(topic_id.getBytes());
                    form_output.write(image_part_1.getBytes());
                    form_output.write(image_part_2.getBytes());
                    form_output.write(data);
                    form_output.write(missing_link.getBytes());

                    form_output.write(image_part_3.getBytes());

                    form_stream.write(form_output.toByteArray());
                    Log.d("TAG","Feed-Connection content legnth :"+Integer.toString(feed_connection.getContentLength()));

                }else {
                    String image_part_1 = new String("--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"richmedia_type\"\r\n\r\n" + "0\r\n");
                    Log.d("TAG", "CONTENT LEGNTH:"+String.valueOf((session_key.length() + feed.length() + sh_career.length() + sh_friend.length() + url_t.length() + url_d.length() + url_a.length() + image.getByteCount() + topic_id.length())));
                    feed_connection.setRequestProperty("Content-Length NO IMG", String.valueOf((session_key.length() + feed.length() + sh_career.length() + sh_friend.length() + url_t.length() + url_d.length() + url_a.length() + image.getByteCount() + topic_id.length())));
                    ByteArrayOutputStream form_output   = new ByteArrayOutputStream();
                    OutputStream form_stream            = new BufferedOutputStream(feed_connection.getOutputStream());
                    form_output.write(session_key.getBytes());
                    form_output.write(feed.getBytes());
                    form_output.write(sh_career.getBytes());
                    form_output.write(sh_friend.getBytes());
                    form_output.write(url_t.getBytes());
                    form_output.write(url_d.getBytes());
                    form_output.write(url_a.getBytes());
                    form_output.write(topic_id.getBytes());
                    form_output.write(image_part_1.getBytes());
                    form_stream.write(form_output.toByteArray());
                    Log.d("TAG","Feed-Connection content legnth :"+ Integer.toString(feed_connection.getContentLength()));
                }
                //write form to connection

                if (feed_connection.getResponseCode() != HttpURLConnection.HTTP_OK)
                {
                    Log.d("TAG","CRAP BROKE MAN");
                    throw new Exception("Carp hit the fan an connection didnt get a OKAY Error Code: " + feed_connection.getResponseMessage() +  feed_connection.getResponseCode());
                }

                InputStream recieved_information = feed_connection.getInputStream();


            }
            catch (Exception the_e)
            {
                System.out.println("Not even" + the_e.getMessage());
                Log.d("TAG", "NOT EVEN" + the_e.getMessage());
            }
        }
  • 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-06-01T08:50:02+00:00Added an answer on June 1, 2026 at 8:50 am

    Content Length is a Http Request Header Property, not a http Request Property.

    This does not set the Content Length in Http Request Header:

    feed_connection.setRequestProperty("Content-Length", String.valueOf((session_key.length() + feed.length() + sh_career.length() + sh_friend.length() + url_t.length() + url_d.length() + url_a.length() + topic_id.length() + image_part_1.length() + image_part_2.length() + missing_link.length() + image_part_3.length())));
    

    Try using HttpURLConnection.setFixedLengthStreamingMode() set the Content Length, for example:

    feed_connection.setFixedLengthStreamingMode(session_key.length() + feed.length() + sh_career.length() + sh_friend.length() + url_t.length() + url_d.length() + url_a.length() + topic_id.length() + image_part_1.length() + image_part_2.length() + missing_link.length() + image_part_3.length());
    

    Hope this helps.

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

Sidebar

Related Questions

I'm doing the following and always get green pins: pin.pinColor = MKPinAnnotationColorRed; [self.mapView addAnnotation:pin];
I use HttpURLConnection to do HTTP POST but I dont always get back the
I have a C# application that needs to get variable-length data passed back from
I always get confused when I am about to use a bit map to
I always get this error when trying to compile my file with Boost::GIL PNG
Why do I always get the following error from Postgres? syntax error at or
I tried many things but I always get cannot convert string to membershipuser from
**In any javaProject in eclipse there we always get .classpath file...like <?xml version=1.0 encoding=UTF-8?>
I'm trying to get this running: JAXB interface But I always get the error
Possible Duplicate: Why do I always get the same sequence of random numbers 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.