FoxPro Programming
Visual Foxpro Post files to a Web Server
Dear Sirs:
I have been trying to upload some .json files to a web server
Dear Rick:
It has been several years since I have needed any help.
I am trying to Post .JSON files to a web server.
I downloaded the latest version of your program and updated the 3 .prg files that were request and inserted the .DLL that was required
Most of the files that the program tries to upload get an Error 500 'Internal Server Error'
One file that is NULL actually gets uploaded - Error 200 Ok (do NOT explain this one to me)
Do you have any suggestions
LOCAL mTEST AS STRING
loHTTP = CREATEOBJECT("wwHTTP")
loHTTP.nHttpPostMode = 2 && Multipart form encoding
* mHOLD1 = "C:\RISWIN\test.txt"
mHOLD1 = "C:\RISWIN\1111_TE_DATA.JSON"
IF FILE(mHOLD1) = .T. THEN
=MESSAGEBOX(mHOLD1)
mTEST = 'loHttp.AddPostFile("file","' + mHOLD1 + '",.T.)'
* mTEST = 'loHttp.AddPostFile("FileVar","' + mHOLD1 + '",.T.)'
=MESSAGEBOX(mTEST)
&mTEST
* loHttp.AddPostKey("txtFileNotes","test note")
lcHTML = loHTTP.Post("https://risdesk.golbm.com/api/files")
=MESSAGEBOX(loHttp.cResultCode)
=MESSAGEBOX(loHttp.cResultCodeMessage)
ELSE
=MESSAGEBOX("NOT FOUND")
ENDIF
I doubt the server is expecting a file upload like what you're doing. The server is much more likely to expect a JSON Content post operation.
To do this:
- Load the JSON to a string
- Set the content type to
application/json
- Post the JSON string as the payload (Post(lcUrl, lcJson))
+++ Rick ---