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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:21:38+00:00 2026-06-13T09:21:38+00:00

my requirement is to receive HTTP Post request using Socket in android(Contents are JSON

  • 0

my requirement is to receive HTTP Post request using Socket in android(Contents are JSON file). When I print socket.getInputStream(), I get:

POST/HTTP/1.1
Content length:41
Content-type: application/json
Host:10.0.2.15:5001
Connection: Keep Alive
User-Agent: Apache HTTPClient/Unavailable(Java 1.4)

CRLF(Carriage return line feed)-  

Actual Contents of JSON<Data>

I used the link https://forums.oracle.com/forums/thread.jspa?messageID=7076709, but it prints only “Content-type: application/json
Host:10.0″(may be for length of 41) in Logcat.

My code is:

    serverSocket = new ServerSocket(portNumber);
    while(true){ 
    socket = serverSocket.accept();
    List<String> headers = new ArrayList<String>();
    String str;
    BufferedReader reader = new BufferedReader(new  InputStreamReader(socket.getInputStream()));
    while ((str = reader.readLine()) != null)
    {
    headers.add(str);
    if (str.startsWith("Content-Length: "))
    {
    break; // and don't get the next line!
    }
    }
    int contentLength = Integer.parseInt(headers.get(headers.size() - 1).substring("Content-Length: ".length()));

   for(int j=0;j<headers.size();j++)
   {
    Log.d("Headers:",headers.get(j));
    }
    StringBuilder requestContent = new StringBuilder();
    int ch;
    for (int i = 0; i < contentLength; i++)
    {
    requestContent.append((char) reader.read());
    }
    Log.d("The request content is: ",""+requestContent);

This is my output:
Headers:
POST / HTTP/1.1
Content-Length: 41

requestContent:
Content-Type: application/json
Host: 10.

Can someone please guide me how it can be done? Thanks in advance!

  • 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-13T09:21:39+00:00Added an answer on June 13, 2026 at 9:21 am
    DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
    conn.bind(serverSocket.accept(), new BasicHttpParams());
    HttpRequest request = conn.receiveRequestHeader();
    conn.receiveRequestEntity((HttpEntityEnclosingRequest)request);
    HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
    System.out.println(EntityUtils.toString(entity));
    

    http://hc.apache.org/httpcomponents-core-ga/tutorial/pdf/httpcore-tutorial.pdf for more reference

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

Sidebar

Related Questions

Requirement: I need to run multiple animations one by one. I'm using onAnimationEnd() to
The requirement of the TCP server: receive from each client and send result back
I have requirement in which I continuously receive messages that needs to be written
I have a requirement that my app, can receive events (e.g. messages) from server
My app has SEND_SMS and RECEIVE_SMS permissions, by publishing it gets android.hardware.telephony requirement. As
I'm building a TCP-based daemon for pre-/post-processing of HTTP requests. Clients will connect to
I have received a requirement to develop a feature to check if 2 email
I have received requirements that ask to normalize text box content when the user
Requirement I have an application with 2 activities, say A and B , with
Requirement : In an app, During the first launch it is required to download

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.