TServerXMLHTTPRequest

Vom Front-End bis SOAP.

Moderator: Moderatoren

Antworten
Benutzeravatar
Rudolf
Programmier-Gott
Programmier-Gott
Beiträge: 1418
Registriert: Mo, 02. Jan 2006 23:03
Wohnort: Salzburg/Österreich
Kontaktdaten:

TServerXMLHTTPRequest

Beitrag von Rudolf »

Hallo,
arbeite gerade an einem Interface für Pushbullet mit der API, funktioniert bis jetzt alles ganz gut mit TServerXMLHTTPRequest, nur muss ich für den File Upload Parameter setzen die im CURL Beispiel mit -d angegeben werden:
curl --header 'Access-Token: <your_access_token_here>' -X POST https://api.pushbullet.com/v2/upload-request -d file_name=image.png -d file_type=image/png
Wie kann ich diese Parameter mit TServerXMLHTTPRequest setzen ?
Hier ein Beispiel das funktioniert, aber mit JSON request statt -d Parameter
Grüße
Rudolf

Code: Alles auswählen

function pushb_ttt()
******************************************************************
// curl --header 'Access-Token: <your_access_token_here>' -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "Note Title", "body": "Note Body"}'
local cUrl  := "https://api.pushbullet.com/v2/pushes"
local cToken := dcc_iniread("FORMCOMMANDER.INI","PUSHBULLET","TESTTOKEN"),xRet
local oHttp := TServerXMLHTTPRequest():New()
local cData := ""
altd()
xRet := oHttp:Open( "POST" , cUrl , .F.)
xRet := oHttp:lIgnoreCertAll := .T.
xRet := oHttp:SetRequestHeader( "Access-Token",  cToken )
xRet := oHttp:SetRequestHeader( "Content-Type",  "application/json" )

cData := '{'
cData += '"type": "file"'
cData += '"file_name": "' + alltrim(mord->attachpdf) + '"'
cData += '"file_type": "application/pdf"'
cData += ', "title": "' + alltrim(mord->subject) + '"'
cData += ', "body": "Ein neues Formular"'
cData += '}'

xRet := oHttp:Send(cData)
cc := oHttp:responseText
prot("pushmsg:" + CRLF + cc + CRLF,addpath(al_path,"pushbullet.log"))
dcqdebug oHttp:status
dcqdebug cc
return .t.

Benutzeravatar
Rudolf
Programmier-Gott
Programmier-Gott
Beiträge: 1418
Registriert: Mo, 02. Jan 2006 23:03
Wohnort: Salzburg/Österreich
Kontaktdaten:

Re: TServerXMLHTTPRequest

Beitrag von Rudolf »

Hallo,
habs gefunden, -d sind Parameter. Wenn man z.B. ein File bei Pushbullet uploaden will, muss vorher eine Request authorization gemacht werden mit Filename und Typ. Im CURL Beispiel https://api.pushbullet.com/v2/upload-request -d file_name=image.png -d file_type=image/png
Mit TServerXMLHTTPRequest geht das so:
xRet := oHttp:Open( "POST" , cUrl , .F.)
xRet := oHttp:lIgnoreCertAll := .T.
xRet := oHttp:SetRequestHeader( "Access-Token", cToken)
cData := 'file_name=' + cFilename + '&file_type=application/pdf'
xRet := oHttp:Send(cData)
cc := oHttp:responseText
dcqdebug oHttp:status
dcqdebug cc
Grüße
Rudolf
Antworten