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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:28:55+00:00 2026-06-18T22:28:55+00:00

I’m trying to send a JSON object to a server on a custom port.

  • 0

I’m trying to send a JSON object to a server on a custom port. I never get any response back from the server however. I think the error might be in the string entity but I can’t figure out what it is.

I’ve had a look at these other issues:

HTTP POST using JSON in Java

post json to java server

How to build a http post request with the correct entity with Java and not using any library?

How to POST data in Android to server in JSON format?

None of them have solved my problem. I’m trying the solution (16 votes) from “HTTP POST using JSON in Java” but it wont work.

Here’s my code:

public void reset() {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        try {
            System.out.println("Start");
            jsonURL = "http://x.x.x.x:3994";
            HttpPost request = new HttpPost(jsonURL);
            StringEntity params = new StringEntity("{\"id\":1,\"method\":\"object.deleteAll\",\"params\":[\"subscriber\"]}");
            request.addHeader("Content-Type", "application/json");
            request.setEntity(params);
            HttpResponse response = httpClient.execute(request);
            System.out.println("End");
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            httpClient.getConnectionManager().shutdown();
        }
    }

The console prints “Start” when it begins but I never get any output from “End” nor any stack trace from the exception. When debugging the debugger stops at the “httpClient.execute(request)” line and never continues.

When I run this command from my terminal:

echo '{"id":1, "method":"object.deleteAll", "params":["subscriber"]} ' | nc x.x.x.x 3994

Everything is executed properly and my request is received by the server.

I think my problem might be with the StringEntity but I’m not sure.

EDIT:

Using Wireshark I was able to capture this packet being sent to the server:

POST / HTTP/1.1 Content-Type: application/json Content-Length: 60
Host: x.x.x.x:3994 Connection: Keep-Alive User-Agent:
Apache-HttpClient/4.2.1 (java 1.5)

{"id":1,"method":"object.deleteAll","params":["subscriber"]}

and this packet coming back from the server:

{"id":null,"error":{"code":-32700,"message":"Unexpected character ('P' (code 80)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')"}}
{"id":null,"error":{"code":-32700,"message":"Unexpected character ('c' (code 99)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')"}}
{"id":null,"error":{"code":-32700,"message":"Unexpected character ('C' (code 67)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')"}}
{"id":null,"error":{"code":-32700,"message":"Unexpected character ('C' (code 67)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')"}}
{"id":null,"error":{"code":-32700,"message":"Unexpected character ('H' (code 72)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')"}}
{"id":null,"error":{"code":-32700,"message":"Unexpected character ('C' (code 67)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')"}}
{"id":null,"error":{"code":-32700,"message":"Unexpected character ('U' (code 85)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')"}}
{"id":null,"error":{"code":-32700,"message":"Line must contain a JSON object"}}
  • 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-18T22:28:56+00:00Added an answer on June 18, 2026 at 10:28 pm

    In your working example, you use nc, which means you are writing directly to TCP, not using HTTP, correct?

    Therefore, your HTTP invocation using HTTPClient is sending unexpected data.
    The errors indicate that the HTTP wrapper is what’s at issue.

    Unexpected character “P” as in “POST”, “C” as in “Content-Type”, etc. The server is reading each line, expecting a raw JSON string, but is getting the HTTP instead.

    Solution: You probably want to use a raw Java socket instead.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am using jsonparser to parse data and images obtained from json response. When
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am confused How to use looping for Json response Array in another Array.
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.