Hello Rick,
I am successfully using wwHttp for making REST API requests. But this time, I need to send quite large data. JSON file is around 1 MB. And I am getting "insufficient stack space" error on loHttp.Post().
lcUrl = "https://externalservicesmanagement-test.alza.cz/dropship-validator/v1/availability?token=8gZMZdw9Rrq%2BRGK2bxKYUS5eHRs%3D"
lcJson = Filetostr(....)
Do wwhttp
loHttp = CREATEOBJECT("wwHttp")
loHttp.cContentType = "application/json"
loHTTP.nConnectTimeOut = 30
loHTTP.cHttpVerb = "POST"
loHttp.AddPostKey(lcJson)
lcResult = loHttp.Post(m.lcUrl, lcJson)
Is there anything I can do to make it work?
Thank you.
Best regards,
Ondrej
What exactly is the error and where exactly is it failing? Are you getting a FoxPro exception, a C5 or is this a message from the server?
A 1mb download should be no problem in an application unless you are extremely memory constrained on your machine or FoxPro is already using a ton of memory.
Also just noticing: You're doing both AddPostKey()
and then adding the data via the Json parameter - only do one or other (the Post()
method is the right place for raw content).
+++ Rick ---
Hi,
I am testing it in simple prg. It is not part of any application so far. I just start Visual FoxPro, set enviroment (paths, variables like date format, century, ...) and run testing prg containing code written in original question.
Here is what i get when it reaches loHttp.Post():
I tried to send same request using .NET HttpClient and there is no problem. So I am able to use wwDotNetBridge with .NET class instead of wwHttp. For me, wwHttp works only for smaller JSONs.
Not sure... as I said works for me (and many others - never heard about this happening) but I then again I have a ton of memory.
Insufficient Stackspace occurs either when FoxPro is out of memory or if you end up in some sort of recursive loop (which actually produces a different Stack Overflow) error.
Could it be that the response is really large?
If you have source code (ie a registered version) you can step through the code and see where it actually blows up in the send operation. That might shed some more light but I can't see why it would blow up other than some resource issue.
Maybe your FoxPro memory settings are really low...
+++ Rick ---
Hi there!
Maybe my comment may help someone looking for help in the future... I just got the same message here in another context (Insufficient stack space) without using wwHttp. In more than 30 years working with VFP, I've never seen this error before.
Although the message looks like a problem with a lack of physical memory, looking at the process consumption at the time of the error, it was normal and very low.
In my case, I realized that the error was due to me saving an extremely large string in the _CLIPTEXT variable. Later, when my code needed to use _CLIPTEXT again, the error occurred.
My solution was just not to save the string in _CLIPTEXT, as it was just for debuging purpose.
So, it's possible that the problem for other people is related to something like this too, a very (very!) long string (over 500,000 characters) being assigned to a variable and then trying to reuse it.
Hope this helps.
Regards,
Stackspace typically refers to FoxPro's working stack (ie. in method memory allocation which is non-heap data). This amount is fairly limited, but FoxPro's memory manager will elevate to heap memory internally when allocating large strings. However, if something is taking up a lot of stack space already when the method is entered the space might so restrained it never gets to the elevation level.
This becomes a problem if code is deeply nested or you're running a recursive loop as the top level stack memory is not released.
It sounds very odd either way. The thing to do is test in a clean environment. Start FoxPro and don't load up anything (CLEAR ALL; CLOSE ALL; RELEASE ALL;
) then try running the code and see if it fails the same way - it shouldn't.
+++ Rick ---