fpParams:={}
AAdd(fpParams,{"emailfrom", "ma...@mail.com"})
AAdd(fpParams,{"sender", "John"})
AAdd(fpParams,{"id", "123"})
AAdd(fpParams,{"attach", "test.pdf"}) // ???
Curl_Func(fpParams, .T.)
FUNCTION Curl_Func(params, postRequest, resultFile)
_cURL:="http://localhost/test.php"
// Default
IF(params == NIL); params := {}; ENDIF
IF(postRequest == NIL); postRequest := .F.; ENDIF
// Init cURL
curl_global_init()
curl := curl_easy_init()
// Do NOT include header in output
curl_easy_setopt(curl, HB_CURLOPT_HEADER, .F.)
// Parameters
FOR EACH param IN params
requestParams += param[1] + "=" + curl_easy_escape(curl, AllTrim(HB_ValToStr(param[2]))) + "&"
NEXT
// Removes trailing &
IF(LEN(requestParams) > 0)
requestParams := LEFT(requestParams, LEN(requestParams) - 1)
ENDIF
IF(postRequest)
// POST request
curl_easy_setopt(curl, HB_CURLOPT_NOSIGNAL, 1)
curl_easy_setopt(curl, HB_CURLOPT_TIMEOUT_MS, 2000)
curl_easy_setopt(curl, HB_CURLOPT_POST, .T.)
curl_easy_setopt(curl, HB_CURLOPT_POSTFIELDS, requestParams)
curl_easy_setopt(curl, HB_CURLOPT_URL, _cURL)
ELSE
curl_easy_setopt(curl, HB_CURLOPT_URL, _cURL + "?" + requestParams)
ENDIF
// Save result to file?
IF(resultFile != NIL)
curl_easy_setopt(curl, HB_CURLOPT_DL_FILE_SETUP, resultFile)
result := .T.
ELSE
curl_easy_setopt(curl, HB_CURLOPT_DL_BUFF_SETUP)
ENDIF
// Execute
curl_easy_perform(curl)
// Load result from buffer into variable
IF(result == NIL)
result := curl_easy_dl_buff_get(curl)
ENDIF
curl_easy_cleanup(curl)
curl_global_cleanup()
RETURN result
Function cURLexe()
Local cPostUrl := 'http://localhost/test.php'
Local cEXE := 'curl.exe '
Local cMode := "-X POST " + cPostURL +''
Local cData := ''
Local cSilent := '-s '
Local cCmd
Local cOut := '-o output.txt '
Local cEmailfrom := 'ma...@mail.com'
Local cSender := 'John'
Local cId := '123'
cData := '-H "Content-Type:multipart/form-data" \ '+;
'-H "cache-control:no-cache" \ '+;
'-H "content-type: multipart/form-data" \ '+;
'-F emailfrom='+cEmailfrom+'\ '+;
'-F sender='+cSender+'\ '+;
'-F id='+cId+'\ '+;
'-F attach=@test.pdf '
cCmd := cEXE + cMode + cData + cSilent + cOut
return hb_run(cCmd)
formdata:='emailfrom=mail@mail.com&sender=John&id=123&'
attach="test.pdf"
oHttp:=createobject('msxml2.xmlhttp.6.0')
oHttp:Open( 'POST', "http://localhost/test.php", .F.)
ohttp:SetRequestHeader("Content-Type" , "application/x-www-form-urlencoded") // if just send string is ok
// ohttp:SetRequestHeader("Content-Type" , "multipart/form-data" ) //if i would like to send file, but i don't know how
oHttp:Send(formdata)
The HBPersistent class allows you to convert any array to text.
After you send the text, the server can convert it back to a Harbour array.
--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/7bf761e0-5de9-41d6-b131-4c01c7f404d5%40googlegroups.com.