How to to fix the error when passing JSON via Socket using PostmanHow do I format a Microsoft JSON date?How can I pretty-print JSON in a shell script?How to parse JSON in JavaHow can I pretty-print JSON using JavaScript?How to parse JSON using Node.js?How do I fix android.os.NetworkOnMainThreadException?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor versionWorking on a java based chatting application using threadingError json parsing
What could a self-sustaining lunar colony slowly lose that would ultimately prove fatal?
Need to read my home electrical meter
What does $!# mean in Shell scripting?
Equivalence relation by the symmetric difference of sets
My employer faked my resume to acquire projects
Can a person survive on blood in place of water?
How to bring application to foreground using Spotlight/keystrokes (named windows/named applications)?
Why would Ryanair allow me to book this journey through a third party, but not through their own website?
Question in discrete mathematics about group permutations
Why does this if-statement combining assignment and an equality check return true?
Value of a binomial series
Is it rude to call a professor by their last name with no prefix in a non-academic setting?
One-way train from Paris to Barcelona
Efficient Algorithm for the boundary of a set of tiles
Is this statement about cut time correct?
How to politely tell someone they did not hit "reply to all" in an email?
Why were helmets and other body armour not commonplace in the 1800s?
Can a British citizen living in France vote in both France and Britain in the European Elections?
Can a US state pass/enforce a law stating that a group of people owe money to the state government?
Defining the standard model of PA so that a space alien could understand
What is a Power on Reset IC?
Website returning plaintext password
What is the function of the corrugations on a section of the Space Shuttle's external tank?
Compaq Portable vs IBM 5155 Portable PC
How to to fix the error when passing JSON via Socket using Postman
How do I format a Microsoft JSON date?How can I pretty-print JSON in a shell script?How to parse JSON in JavaHow can I pretty-print JSON using JavaScript?How to parse JSON using Node.js?How do I fix android.os.NetworkOnMainThreadException?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor versionWorking on a java based chatting application using threadingError json parsing
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
My team is trying to build the application that detects the movement of the object and sending those information(JSON) to server(backend using java). I have tried to get JSON data via socket, but it shows this kind of error. I'm using postman to send JSON to test. Another question is using tomcat to get and post data from browser is better than using socket in this scenario?
public class ThreadedEchoServer
static final int PORT = 5000;
public static void main(String args[])
ServerSocket serverSocket = null;
Socket socket = null;
try
serverSocket = new ServerSocket(PORT);
catch (IOException e)
e.printStackTrace();
while (true)
try
socket = serverSocket.accept();
System.out.println("Client connect...");
catch (IOException e)
System.out.println("I/O error: " + e);
// new thread for a client
new EchoThread(socket).start();
public class EchoThread extends Thread
protected Socket socket;
public EchoThread(Socket clientSocket)
this.socket = clientSocket;
public void run()
InputStream inp = null;
BufferedReader brinp = null;
PrintWriter out = null;
try
inp = socket.getInputStream();
brinp = new BufferedReader(new InputStreamReader(inp));
// out = new PrintWriter(socket.getOutputStream(), true);
catch (IOException e)
return;
String line;
while (true)
try
line = brinp.readLine();
if ((line == null) catch (IOException e)
e.printStackTrace();
return;
Here is json that I used Postman to post request
"id": 963,
"result": "United States",
"cook": 30
But I got this error
Client connect...
Exception in thread "Thread-0" org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
at org.json.JSONTokener.syntaxError(JSONTokener.java:505)
at org.json.JSONObject.<init>(JSONObject.java:215)
at org.json.JSONObject.<init>(JSONObject.java:399)
at EchoThread.run(EchoThread.java:34)
java json sockets
add a comment |
My team is trying to build the application that detects the movement of the object and sending those information(JSON) to server(backend using java). I have tried to get JSON data via socket, but it shows this kind of error. I'm using postman to send JSON to test. Another question is using tomcat to get and post data from browser is better than using socket in this scenario?
public class ThreadedEchoServer
static final int PORT = 5000;
public static void main(String args[])
ServerSocket serverSocket = null;
Socket socket = null;
try
serverSocket = new ServerSocket(PORT);
catch (IOException e)
e.printStackTrace();
while (true)
try
socket = serverSocket.accept();
System.out.println("Client connect...");
catch (IOException e)
System.out.println("I/O error: " + e);
// new thread for a client
new EchoThread(socket).start();
public class EchoThread extends Thread
protected Socket socket;
public EchoThread(Socket clientSocket)
this.socket = clientSocket;
public void run()
InputStream inp = null;
BufferedReader brinp = null;
PrintWriter out = null;
try
inp = socket.getInputStream();
brinp = new BufferedReader(new InputStreamReader(inp));
// out = new PrintWriter(socket.getOutputStream(), true);
catch (IOException e)
return;
String line;
while (true)
try
line = brinp.readLine();
if ((line == null) catch (IOException e)
e.printStackTrace();
return;
Here is json that I used Postman to post request
"id": 963,
"result": "United States",
"cook": 30
But I got this error
Client connect...
Exception in thread "Thread-0" org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
at org.json.JSONTokener.syntaxError(JSONTokener.java:505)
at org.json.JSONObject.<init>(JSONObject.java:215)
at org.json.JSONObject.<init>(JSONObject.java:399)
at EchoThread.run(EchoThread.java:34)
java json sockets
You have shown us some socket code, yet you say you are using Postman. Which method are you actually using?
– Tim Biegeleisen
Mar 24 at 2:19
@TimBiegeleisen Hello Tim. I'm using POST request to send data.
– newbie
Mar 24 at 2:44
@TriDo Postman is communicating using HTTP (which sits on top of TCP); your server code is expecting "raw" TCP. So, the Postman TCP stream will likely start with the verb and wherever you're posting to (assuming you are POSTing): "POST /some/endpoint/here HTTP/1.1". That won't deserialize into JSON.
– Not a JD
Mar 24 at 4:22
@NotaJD Hi Nota, Can you give me any suggestion ?
– newbie
Mar 24 at 4:54
add a comment |
My team is trying to build the application that detects the movement of the object and sending those information(JSON) to server(backend using java). I have tried to get JSON data via socket, but it shows this kind of error. I'm using postman to send JSON to test. Another question is using tomcat to get and post data from browser is better than using socket in this scenario?
public class ThreadedEchoServer
static final int PORT = 5000;
public static void main(String args[])
ServerSocket serverSocket = null;
Socket socket = null;
try
serverSocket = new ServerSocket(PORT);
catch (IOException e)
e.printStackTrace();
while (true)
try
socket = serverSocket.accept();
System.out.println("Client connect...");
catch (IOException e)
System.out.println("I/O error: " + e);
// new thread for a client
new EchoThread(socket).start();
public class EchoThread extends Thread
protected Socket socket;
public EchoThread(Socket clientSocket)
this.socket = clientSocket;
public void run()
InputStream inp = null;
BufferedReader brinp = null;
PrintWriter out = null;
try
inp = socket.getInputStream();
brinp = new BufferedReader(new InputStreamReader(inp));
// out = new PrintWriter(socket.getOutputStream(), true);
catch (IOException e)
return;
String line;
while (true)
try
line = brinp.readLine();
if ((line == null) catch (IOException e)
e.printStackTrace();
return;
Here is json that I used Postman to post request
"id": 963,
"result": "United States",
"cook": 30
But I got this error
Client connect...
Exception in thread "Thread-0" org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
at org.json.JSONTokener.syntaxError(JSONTokener.java:505)
at org.json.JSONObject.<init>(JSONObject.java:215)
at org.json.JSONObject.<init>(JSONObject.java:399)
at EchoThread.run(EchoThread.java:34)
java json sockets
My team is trying to build the application that detects the movement of the object and sending those information(JSON) to server(backend using java). I have tried to get JSON data via socket, but it shows this kind of error. I'm using postman to send JSON to test. Another question is using tomcat to get and post data from browser is better than using socket in this scenario?
public class ThreadedEchoServer
static final int PORT = 5000;
public static void main(String args[])
ServerSocket serverSocket = null;
Socket socket = null;
try
serverSocket = new ServerSocket(PORT);
catch (IOException e)
e.printStackTrace();
while (true)
try
socket = serverSocket.accept();
System.out.println("Client connect...");
catch (IOException e)
System.out.println("I/O error: " + e);
// new thread for a client
new EchoThread(socket).start();
public class EchoThread extends Thread
protected Socket socket;
public EchoThread(Socket clientSocket)
this.socket = clientSocket;
public void run()
InputStream inp = null;
BufferedReader brinp = null;
PrintWriter out = null;
try
inp = socket.getInputStream();
brinp = new BufferedReader(new InputStreamReader(inp));
// out = new PrintWriter(socket.getOutputStream(), true);
catch (IOException e)
return;
String line;
while (true)
try
line = brinp.readLine();
if ((line == null) catch (IOException e)
e.printStackTrace();
return;
Here is json that I used Postman to post request
"id": 963,
"result": "United States",
"cook": 30
But I got this error
Client connect...
Exception in thread "Thread-0" org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
at org.json.JSONTokener.syntaxError(JSONTokener.java:505)
at org.json.JSONObject.<init>(JSONObject.java:215)
at org.json.JSONObject.<init>(JSONObject.java:399)
at EchoThread.run(EchoThread.java:34)
java json sockets
java json sockets
asked Mar 24 at 2:16
newbienewbie
175
175
You have shown us some socket code, yet you say you are using Postman. Which method are you actually using?
– Tim Biegeleisen
Mar 24 at 2:19
@TimBiegeleisen Hello Tim. I'm using POST request to send data.
– newbie
Mar 24 at 2:44
@TriDo Postman is communicating using HTTP (which sits on top of TCP); your server code is expecting "raw" TCP. So, the Postman TCP stream will likely start with the verb and wherever you're posting to (assuming you are POSTing): "POST /some/endpoint/here HTTP/1.1". That won't deserialize into JSON.
– Not a JD
Mar 24 at 4:22
@NotaJD Hi Nota, Can you give me any suggestion ?
– newbie
Mar 24 at 4:54
add a comment |
You have shown us some socket code, yet you say you are using Postman. Which method are you actually using?
– Tim Biegeleisen
Mar 24 at 2:19
@TimBiegeleisen Hello Tim. I'm using POST request to send data.
– newbie
Mar 24 at 2:44
@TriDo Postman is communicating using HTTP (which sits on top of TCP); your server code is expecting "raw" TCP. So, the Postman TCP stream will likely start with the verb and wherever you're posting to (assuming you are POSTing): "POST /some/endpoint/here HTTP/1.1". That won't deserialize into JSON.
– Not a JD
Mar 24 at 4:22
@NotaJD Hi Nota, Can you give me any suggestion ?
– newbie
Mar 24 at 4:54
You have shown us some socket code, yet you say you are using Postman. Which method are you actually using?
– Tim Biegeleisen
Mar 24 at 2:19
You have shown us some socket code, yet you say you are using Postman. Which method are you actually using?
– Tim Biegeleisen
Mar 24 at 2:19
@TimBiegeleisen Hello Tim. I'm using POST request to send data.
– newbie
Mar 24 at 2:44
@TimBiegeleisen Hello Tim. I'm using POST request to send data.
– newbie
Mar 24 at 2:44
@TriDo Postman is communicating using HTTP (which sits on top of TCP); your server code is expecting "raw" TCP. So, the Postman TCP stream will likely start with the verb and wherever you're posting to (assuming you are POSTing): "POST /some/endpoint/here HTTP/1.1". That won't deserialize into JSON.
– Not a JD
Mar 24 at 4:22
@TriDo Postman is communicating using HTTP (which sits on top of TCP); your server code is expecting "raw" TCP. So, the Postman TCP stream will likely start with the verb and wherever you're posting to (assuming you are POSTing): "POST /some/endpoint/here HTTP/1.1". That won't deserialize into JSON.
– Not a JD
Mar 24 at 4:22
@NotaJD Hi Nota, Can you give me any suggestion ?
– newbie
Mar 24 at 4:54
@NotaJD Hi Nota, Can you give me any suggestion ?
– newbie
Mar 24 at 4:54
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320165%2fhow-to-to-fix-the-error-when-passing-json-via-socket-using-postman%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320165%2fhow-to-to-fix-the-error-when-passing-json-via-socket-using-postman%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You have shown us some socket code, yet you say you are using Postman. Which method are you actually using?
– Tim Biegeleisen
Mar 24 at 2:19
@TimBiegeleisen Hello Tim. I'm using POST request to send data.
– newbie
Mar 24 at 2:44
@TriDo Postman is communicating using HTTP (which sits on top of TCP); your server code is expecting "raw" TCP. So, the Postman TCP stream will likely start with the verb and wherever you're posting to (assuming you are POSTing): "POST /some/endpoint/here HTTP/1.1". That won't deserialize into JSON.
– Not a JD
Mar 24 at 4:22
@NotaJD Hi Nota, Can you give me any suggestion ?
– newbie
Mar 24 at 4:54