ofURLFileLoader bugfix for sending POST#8428
Merged
Merged
Conversation
…andling if making a GET req
Contributor
Author
|
Oh, and I also notice that the ofHttpResponse error variable is only set when there is a connection error. It is not actually set on a successful response. Maybe this should be a separate issue? I tried setting the |
54 tasks
Member
|
Thanks Dan!! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
So I am a little lazy and decided to use ofURLFileLoader for basic REST stuff to a local ollama server instead of bothering with ofxHTTP. It's just a thin wrapper for HTTP and it's built into the core anyway...
I noticed that GETs work fine however trying to POST a body with stringified JSON resulted in a 405 METHOD NOT ALLOWED error. Enabling verbose in the request showed that, in my case, the actual request type being made was a GET even though I set the request method to POST.
I was able to fix this by making sure the libcurl method opts are set before dealing with the request body / POST data handling. This broke GET so only setting the POST handling stuff if not doing a GET was the fix. If the request is a GET, the request body should be ignored anyway, I believe. I think libcurl is making some assumptions in the background when setting some of these options, so order might be important, ie. setting POSTFIELDS (even disabling) might trigger it to change the request type.
My original tests are big made using ofxLua and the
of_v20250330_osx_releasebuild:The equivalent C++ should be something like:
The output in my simple test is:
I also tested imageLoaderWebExample which works fine.