FoxPro Programming
Post a File
We are trying to post a file using wwHTTP. Was wondering if we could be pointed in the right direction. We are new to CURL and Posting Files.
Here is the sample CURL command client gave us to use. We need to capture the return code to make sure the file was uploaded successfully (code 200):
curl -X POST https://acc.appiancloud.com/webapi/per-capita-file
--data-binary "@G:\Curl\LU0123_09302020.txt"
-H "Appian-API-Key: eyJ0eXAiOiJKV1QiLCJhbG....sample key"
-H "Appian-Document-Name: LU0123.txt" -H "Local: 123" -H "Month: 9" -H "Year: 2020" -H "Overwrite: N"
Our VFP Code using code samples:
loHttp = CREATEOBJECT("wwHTTP")
loHttp.AddPostKey(" --data-binary @G:\Curl\LU0190_09302020.txt")
loHttp.AddPostKey("Appian-API-Key: ","eyJ0eXAiOiJKV1QiLCJhbG....sample key")
loHttp.AddPostKey("Appian-Document-Name: ","LU0190_09302020.txt")
loHttp.AddPostKey("Local: ","123")
loHttp.AddPostKey("Month: ","9")
loHttp.AddPostKey("Year: ","2020")
loHttp.AddPostKey("Overwrite: ","N")
lcText=""
lnText=0
* We've tried a variation of calls with the same error result (sample cURL)
lcText = loHttp.HTTPGet("https://acc.appiancloud.com/suite/webapi/per-capita-file")
lcText = loHttp.Post("https://acc.appiancloud.com/webapi/per-capita-file")
Error = "{"resource":"\/suite\/webapi\/per-capita-file","error":"APNX-1-4187-000","message":"Authentication failed. Please check your credentials and try again.","title":"An Error Has Occurred"}"
Thanks in advance,
-Ric
All those values are headers according to the curl
command, not post buffer values. Try using .AddHeader()
instead of .AddPostKey()
.
The post buffer looks like it expects a file to be uploaded which probably is just the content of the file. Hard to say whether the file is expected to be an HTTP form upload or just the raw data buffer. I would guess the latter:
loHttp.AddPostKey(FileToStr("datafile.txt"))
+++ Rick ---