Http control post json error


Ryan Sytsma

David, I am using an HTTP control to post data to a .NET Web API method.

Here is the AB script:

Here is the json payload. You will notice that the key values are correct but the key names are not. The key names are showing previous test values. ??



Ryan Sytsma

I forgot to show you the header



DecSoft

Hello Ryan,

At least to discard it, please, remove the "_Compiled" and the "_Cache" folders, then compile the app again and try it. Doing this we can assert that the code is the latest compiled one, not any possible waste in the cache... because it's quite rare... that some of the keys appear fine but no others...



Ryan Sytsma

I removed both folders and recompiled

Still getting 500 error and the submitted json payload looks even worse.



DecSoft

Hello Ryan,

A couple of things. It's quite rare that you get an more or less entire different JSON payload... if you are using the same code to do the HTTP call... Anyway, I am thinking that maybe the problem is that some of the keys that you are using are in fact variables in the app, and, for that reason, we get an "undefined" for that keys...

Look at the below code, which is a test that I made here in a clean app:

The values are fakes, of course, but, they JSON payload is the below one:

... at least the keys are respected... so please, take a look and confirm that the keys that you are using are not already app variables, which may are causing the problem.



Ryan Sytsma

thanks David, I know for sure that they are app variables elsewhere. Maybe I will prefix these different in my Web Api so they are always unique. I had just assumed that the key/value collection would not use local variables.



DecSoft

Hello Ryan,

Yes; it's not the best that variables can interfere here, but, the fact is like that. So, we need to be sure that we don't use existing variable names / identifiers for the HTTP keys. Since the HTTP keys probably cannot be changed (that is, the server can expect some specific key names), it's better to change the variables names / identifiers.

P.S. If you take a look at the generated Javascript code, it's possible to see if what we are talking about is what really happend, since we can see the Javascript code and how the keys are established before the HTTP call is made.



Ryan Sytsma

David, thanks for your help.

I changed my Json model in the API to expect keys that are prefixed with "api_". That has worked very well.

Am I the only one posting in the forums?

:)

DecSoft

Hello Ryan,

No problem. I also post in the forum, so don't worry! :-)


Everybody can read the DecSoft support forum for learning purposes, however only DecSoft customers can post new threads. Purchase one or more licenses of some DecSoft products in order to give this and other benefits.

This website uses some useful cookies to store your preferences.

I agree. Hide this note. Give me more information.