JSON API
Posted: Sat Nov 27, 2021 10:29 am
I need a help.
For this request
curl -X POST "https://esite/api/publicApi" -H "accept: text/plain" -H "ApiKey: xxxxx" -H "Content-Type: application/json" -d "{\"registrationNumber\":\"yyyy\"}"
this work fine:
oRestApi := Win_OleCreateObject( "MSXML2.ServerXMLHTTP" )
oRestApi:setTimeouts(nTimeout * 1000 /* nResolve */ , nTimeout * 1000 /* nConnect*/ , nTimeout * 1000 /* nSend */, nTimeout * 1000 /* nReceive
*/ )
oRestApi:Open( "POST", cUrl, .F. )
oRestApi:setRequestHeader( "accept", "text/plain")
oRestApi:setRequestHeader( "ApiKey", "xxxxxx" )
oRestApi:setRequestHeader( "Content-Type", "application/json")
cBody1 := { => }
cBody1 ["registrationNumber"] := yyyyy
cBody := hb_jsonEncode( cBody1 , .F. )
oRestApi:Send(cBody)
cReturn := hb_jsonDecode( oRestApi:ResponseText() )
Question is how to code this:
curl -X POST "https://esite/api/publicApi" -H "accept: text/plain" -H "ApiKey: xxxx" -H "Content-Type: multipart/form-data" -F "ublFile=@test.xml;type=text/xml"
For this request
curl -X POST "https://esite/api/publicApi" -H "accept: text/plain" -H "ApiKey: xxxxx" -H "Content-Type: application/json" -d "{\"registrationNumber\":\"yyyy\"}"
this work fine:
oRestApi := Win_OleCreateObject( "MSXML2.ServerXMLHTTP" )
oRestApi:setTimeouts(nTimeout * 1000 /* nResolve */ , nTimeout * 1000 /* nConnect*/ , nTimeout * 1000 /* nSend */, nTimeout * 1000 /* nReceive
*/ )
oRestApi:Open( "POST", cUrl, .F. )
oRestApi:setRequestHeader( "accept", "text/plain")
oRestApi:setRequestHeader( "ApiKey", "xxxxxx" )
oRestApi:setRequestHeader( "Content-Type", "application/json")
cBody1 := { => }
cBody1 ["registrationNumber"] := yyyyy
cBody := hb_jsonEncode( cBody1 , .F. )
oRestApi:Send(cBody)
cReturn := hb_jsonDecode( oRestApi:ResponseText() )
Question is how to code this:
curl -X POST "https://esite/api/publicApi" -H "accept: text/plain" -H "ApiKey: xxxx" -H "Content-Type: multipart/form-data" -F "ublFile=@test.xml;type=text/xml"