Tcp client altering request

I am using the TCPClient on an Electron to pass data to a database through a private server. During the process the request is altered and the “&” between variables is being replaced with the html entity '& amp ;". The server then throws a “400 Bad Request” error. (I added spaces to prevent the entity from being automatically converted)

After the request is string is constructed the data passed appears as:
‘GET /postScript.php?var1=1&var2=2&var3=3’ … etc.

However, the server is replying with an error and suggesting that the string is being sent as:
‘GET /postScript.php?var1=1 & amp ;var2=2& amp ;var3=3’

I assume this is happening client side as this has worked before using a WiFi shield on an arduino using nearly identical code. Is there a special way that I need to format requests for the Electron TCPClient?


Hi @smmdc

I don’t think this is happening on the firmware side. I did a search in the Particle github firmware repo for “amp” and the only places that turn up are in the test harness, not in the shipping code. So that lowers the probability of firmware doing this change to you on the device.

That leads to further questions:

  1. Are there any proxies or other intermediary hosts between your device (well, the cellular network really) and the private server that is getting the bad data?

  2. Are you using a Particle SIM or a third-party SIM? I am not aware of any differences in this area, but if someone else tries to recreate the problem we need to know.

  3. It looks like you are doing a GET request, which is not the normal way to post data on the web. Did you mean to be doing a POST?

  4. Can you show us the entire HTTP header and data that you write to TCPClient? And in fact, without seeing your code and knowing more about your setup, there is little we do to help.

1 Like