Hi Rick,
In CURL, I have this code:
curl --location --request POST 'http://127.0.0.1:2008/sa/api/lra/v1/actes/prevalider' \
--header 'Content-Type: application/json' \
--data-raw '{
"flux":"PD94bWwgdmVyc2lvbj0iMS4wIiBlbmN..."
}'
So, my VFP code is:
loHTTP = CREATEOBJECT ('wwHTTP')
WITH loHTTP
.nConnectTimeOut = 30
.lUseLargePostBuffer = .T.
.addheader("Content-Type", "application/json")
.nHttpPostMode = 2
.cContentType = "application/json"
.AddPostKey("flux", STRCONV (FILETOSTR (Myfile), 13))
ENDWITH
But I get an error related to the settings
I tried with or without .nHttpPostMode
and .cContentType
, without success
An idea ?
thanks in advance
You don't need .addHeader()
as setting the content type will set this automatically. Adding it this way adds two headers (which could potentially be rejected by the target server).
You're making posting JSON way too complicated:
loHttp = CREATEOBJECT("wwHttp")
loHttp.cContentType = "application/json"
lcResut = loHttp.Post(lcUrl, lcJson)
Note you do not want to pass 'form variables' but rather raw data. So you can use the .Post()
syntax above, or if you use the old syntax:
loHttp = CREATEOBJECT("wwHttp")
loHttp.cContentType = "application/json"
loHttp.AddPostKey(lcJson) && note: no key which sets the entire buffer
lcResult = loHttp.HttpGet(lcUrl)
+++ Rick ---
Thank you Rick.
It didn't work in my case. But "manually", no worries:
.addheader ("Content-Type", "application / json")
lcJSON = '{"flux":"Base64Base64..."}'
.AddPostKey ("", lcJSON)
Are you on an old version that doesn't support cContentType
? That should always set the header, and the parameterless AddPostKey()
has been there for a long time as well (5.x at least).
+++ Rick ---