0

I am doing a JSON POST via $.post(), but it seems it is changing my POST contents from JSON to Query string parameters.

I POST the following to the end-point:

$.post('/proxy/endpoint.json', { "query": {"test": true, "msg": "test" } });

The server handling the request shows the following logs:

ERROR - Bad POST params: query%5Btest%5D=true&query%5Dmsg%5Btest

Request flow:

JavaScript -> IIS Rewrite Proxy -> Nginx -> Java Server endpoint, e.g. localhost:4000/endpoint.json

NOTE: I've tested the same POST request via Postman directly to IIS Server, which works fine. So it can only be my Jquery which is causing this problem.

Any tips on how I can improve this?

1
  • Your code POSTs fine for me when I try it. Can you share the rest of your JavaScript? Commented Oct 4, 2019 at 8:35

2 Answers 2

1

back to jQuery.post , and pass the right params object

for you example change your code to

$.post('/proxy/endpoint', {"test": true, "msg": "test" });
Sign up to request clarification or add additional context in comments.

4 Comments

Unfortunately I cannot change the JSON object being passed through, as the server is expecting it in that format.
don't pass it directly to jQuery.Post , try to use it as " SERVERJSON.query " . use only the value of query in JSON object passed through
I got a hint from your response, thus what you meant was to use the string representation of the JSON object.
Yes, what i mean to use string of json object and pass the value of key " query " (ex: obj.query)
0

In this case the answer was to use the string representation of the JSON object.

$.post('/proxy/endpoint.json', JSON.stringify({ "query": {"test": true, "msg": "test" } }));

This turned out to work.

Thanks to Ahmed El-sayed for leading me in the right direction.

1 Comment

I request you to mark the helpful suggestion as an answer. This will help other people who face the same issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.