View Full Version : REST API Post Problem returning Json object

Sam Neuner
30-Apr-2020, 04:35 PM
I have a Post in a REST API. It has been returning a Json object to indicate the success or failure of the Post. All of a sudden it is not returning that object. I have not changed the code and I have another Post procedure that has the same return code in it and it is working fine. Any ideas why a return object is not returning? Yes, I am sure it is going through the code, it was before.

30-Apr-2020, 05:44 PM
have you checked what it is returning?

test with postman

Sam Neuner
30-Apr-2020, 06:11 PM
I just tested this from my computer (not the customer's development computer from the studio) and I do not get the error. When it is run from the studio no handle is returned for the hoRequestJson

Sam Neuner
30-Apr-2020, 06:13 PM
How can I use Postman to test a Post that needs to send a JSON object? I have been wanting to do this for other testing.

30-Apr-2020, 06:48 PM
you set up a post in postman and in the body you select raw and type json and paste your json in the body area

Sam Neuner
30-Apr-2020, 06:50 PM
Yes, I just learned that. Thanks.

Sam Neuner
1-May-2020, 10:42 AM
I think I have identified the problem. I attempted to Login and test the call to the REST API to verify the user. It seems that when on the development computer where both the REST API and the calling WebApp are running that the call does not return the Json object. I found that it does work if I call the REST API from the development computer using a desktop app. Am I crazy or is there a problem when both web applications are running on the same computer?

1-May-2020, 10:51 AM
what status code is returned?

1-May-2020, 10:52 AM
whats the statuscode returned when it doesnt work

Sam Neuner
1-May-2020, 11:06 AM
I do not get an error, the return Json object is 0 and therefore the Login (or Post) cannot be confirmed.

1-May-2020, 11:26 AM
but whats the status code returned

Sam Neuner
1-May-2020, 11:57 AM
I do not understand what you mean by status code? Here is the code:

Get HttpGetJson of oJsonHttp "localhost" ("/CherokeeRest/Backflow/TesterInfo/" + sLoginName) (&bOk) to hoJson

The hoJson = 0! There is no error because the call is successful (in either this Login or Post) but cannot verify by checking the message we put in the return Json.

I just confirmed that when using the program in the active web server it works, just not when using in the studio.

1-May-2020, 12:03 PM
the HTTP status code

best thing is to call it via postman or you can also use fiddler to sniff on the http traffic to see whats happening and will also allow you to see the actual body returned

Sam Neuner
1-May-2020, 12:24 PM
It works in the Postman, just not from the Studio.

Sam Neuner
1-May-2020, 12:26 PM
Just to elaborate further, I am returning a Json object with a message/error based on the result of the Get/Post. It is this object that is not being returned when run from the Studio.

1-May-2020, 01:50 PM
then the call must be bad in some way.

are you able to debug it? Does it get called properly and execute properly? (just to make sure you did write both the server and client?)

download fiddler and compare the two calls and see whats different

you may be missing a header on the client call for example the accept header

1-May-2020, 02:19 PM
You can ask the oJsonHttp object for the last error like this.

Get TransferErrorDescription of oJsonHttp to sErr
Send UserError sErr "Transfer failed!"

Sam Neuner
1-May-2020, 02:41 PM
Yes, I have written both server and client. This App works find when executed on the Live server. This same code which is ported to the Live server where it works correctly does not when executed in the Studio! It is the same code, same App different result.

Sam Neuner
1-May-2020, 02:51 PM
Get "Http request failed"

1-May-2020, 06:01 PM
Get "Http request failed"

Which does not help...
How about the http status code (that you can see if Fiddler or...)

Get ResponseStatusCode of hoHttp to iStatus

Fiddler gives you a lot more info, but without a status code you are basically driving blind as to what is happening.

Sam Neuner
1-May-2020, 06:08 PM
Status Code = 0.

2-May-2020, 05:16 AM
no such thing as a status code 0. that and the error message tells me it probably never calls the server code

have you actually had the debugger running on the server code when this happens and did it actually call the server code?

and again download fiddler to shoe the communication. you can watch both the good and bad and see the difference.

if it is a get you can try the same url in the browser as well

Sam Neuner
2-May-2020, 09:43 AM
Thanks for the reminder, I forgot that I can have multiple instances of the Studio running so that I can debug the REST while running the other WebApp. When calling from the other WebApp (using "localhost") it does not go through. If I use the same code in the desktop app, it does go through. What could be the difference? I also tried calling the customer's webserver with this same call and it does not go through. I know the REST is working property because Postman and the browser both return the Json object. Could it be that a setting needs to be set in the cJsonHttpTransfer object?

Sam Neuner
2-May-2020, 09:46 AM
BTW, have you tried a similar test?

Sam Neuner
2-May-2020, 10:36 AM
This is what I got from Fiddler: Result 502

[Fiddler] The connection to 'localhost' failed. <br />Error: ConnectionRefused (0x274d). <br />System.Net.Sockets.SocketException No connection could be made because the target machine actively refused it

Garret Mott
2-May-2020, 10:44 AM
So is port 443 open on the machine?

Sam Neuner
2-May-2020, 11:59 AM
Do not think is was! When I changed the HTTP transfer to use the normal port (80?) it worked. The SSL and ifSecure were set in the transfer object so it was using port 443? I know nothing about opening up a port but looked it up on internet but have been unsuccessful in getting it open or at least the app does not work using SSL.

2-May-2020, 12:00 PM
oin your dev machines iis do you actually have HTTPS configured? if not thats why it isnt working

2-May-2020, 12:01 PM
it isnt just opening a port. the port is actually open on a local machine. In order for HTTPS to work you have to create a binding in IIS to HTTPS port 443 and assign a SSL certificate

Sam Neuner
2-May-2020, 12:08 PM
I do not know how to do this. Now that I can turn off the SSL for testing I may just do that. What are the steps in IIS to set HTTPS up if I want to?

2-May-2020, 12:13 PM
in IIS manager go to your site (probably default) right click and select 'Edit Bindings'

you will probably see

HTTP port 80

click add

select type HTTPS and port 443.

then you need to select a certificate.

You can create a self signed certificate under Server Certificates in IIS. After creating it you need to trust the cert so you dont get a warning

Garret Mott
2-May-2020, 12:15 PM
I'd google that. Lots of answers out there & this isn't DF specific.

Sam Neuner
2-May-2020, 02:06 PM
I managed to create the certificate and went through the process of trusting from google searches but can not seem to get it trusted. Not really a problem though, I can click Yes each time.

Thanks so much for your help. This is an area for which I have no experience.

2-May-2020, 06:07 PM
you need to install the cert. when installing make sure to select 'Place in the following store' and then select 'Trusted Root Certification Authorities'

Sam Neuner
2-May-2020, 06:51 PM
It is listed under Certificates there.

3-May-2020, 05:33 AM
if it isnt in trusted root cert authorities it will not work in the browser

normally when you get an SSL cert you buy it for a domain and you get it from a trusted authority. (trusted by browsers), this is self signed so it isnt from a trusted authority so you have to manually tell your computer to add it to trusted authorities

Sam Neuner
3-May-2020, 08:45 AM
I call call both the REST and the WebApp from the browser with no problem.

3-May-2020, 01:21 PM
if you can call it with HTTPS and you do not get a warning about the certificate then you installed the cert properly

Sam Neuner
3-May-2020, 02:01 PM
I cannot call it from the browser, I get the warning. However, my certificate is listed under Trusted Root Certification Authorities in mmc!