FoxPro Programming
Visual Foxpro Post files to a Web Server
Gravatar is a globally recognized avatar based on your email address. Visual Foxpro Post files to a Web Server
  Edward K. Marois
  All
  Mar 14, 2024 @ 05:51am

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
Gravatar is a globally recognized avatar based on your email address. re: Visual Foxpro Post files to a Web Server
  Rick Strahl
  Edward K. Marois
  Mar 14, 2024 @ 09:48am

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 ---

Gravatar is a globally recognized avatar based on your email address. re: Visual Foxpro Post files to a Web Server
  Edward K. Marois
  Rick Strahl
  Mar 15, 2024 @ 04:41am

Dear Rick:

Thanks for the responce

It appears that the 'Name' of the file that I was tyring to upload is extremely relevant

Making up a company name is a bad thing.

All is well and working.

Gravatar is a globally recognized avatar based on your email address. re: Visual Foxpro Post files to a Web Server
  Rick Strahl
  Edward K. Marois
  Mar 15, 2024 @ 09:59am

What is the API signature?

+++ Rick ---

© 1996-2024