JSON parsing

Avatar
  • updated

I created a TcpServer with a JSON parser:

Image 4625

I added a string parser with a token :

Image 4627


I use Postman and send :

{"TestData":{"Data1":"1"}}


ComfortClick receives data:

POST / HTTP/1.1

Content-Type: text/plain

User-Agent: PostmanRuntime/7.32.3

Accept: */*

Postman-Token: e79d7b2e-8a0a-4ef6-bd47-8d5cc7e8c6f3

Host: 192.168.1.7:16900

Accept-Encoding: gzip, deflate, br

Connection: keep-alive

Content-Length: 26


{"TestData":{"Data1":"1"}}


But the parser throws an error:

Devices : 15.08.2023 14:54:09 : Error : Devices\Test\String : Error parsing received data. Unexpected character encountered while parsing value: P. Path , line 0, position 0. w Newtonsoft.Json.JsonTextReader.ParseValue()

w Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)

w Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)

w ComfortClick.Tasks.Common.ReceiverBase.OnDataReceived(String data)


It looks like the header is being passed to the parser, not the JSON itself.

Bug or my configuration error?

How to disable header passing to parser?

Tested on ComfortClick v 4.9.36

Avatar
Jürgen Jürgenson
Quote from Krzysztof Szczepański

I have everything configured as in the file I exported. Postman is installed locally and when sending http, data reaches Comfortclick without any problems, both in http and https.

This is what it looks like:

http:

Image 4636

https:

Image 4635

Now I have two problems:
1. JSON parsing doesn't work - probably due to passing header to parser, workaround is regex
2. TCPServer does not decrypt https connections

Thanks for your help, but I guess the problems lie deeper in CC.
I am waiting for their support :)

I now got as far you did and im facing same problems - http works but https does not. Strange that for me even the regex parser isnt working - i can get the correct response, thought i could parse it with regex so only the json value remains but it doesnt want to parse its values even if i send it with a program. If i turn off all headers and send it as post i still get: POST / HTTP/1.1 {"TestData":{"Data1":"6"}} and the first part is messing up the json parser.

If you can modify the postman mock api server then that works for me as much as i tested it. Its able to send the value without any headers and then the json parser works for me. If postman runs as a service and mirrors the received value to mock server then it should work hopefully.  Something like this: https://learning.postman.com/docs/sending-requests/capturing-request-data/capturing-http-requests/

Avatar

here you have a working regex parser :test-regex.bos

(?<={\"TestData\":{\"Data1\":")\d+

Currently, the most important thing for me is to make https work.

I can bypass the broken JSON parser.

CC Support: Knock... Knock... :)

Avatar

Reply from CC :

Regarding the issue you're facing, the TCPserver receives raw data, so you can only use http connection. Incrypted https connection will not work and you will get those strange symbols that you're experiencing.

If you want to use https and encrypted data, use our RPC connection instead of TCPserver.