Translate a PHP function to Delphi

I need the following PHP/CURL function translated into a Delphi/WinInet function. I'll pay $30 only. This should be a ten minute job for any one familier with Delphi and Windows API.

Microsoft provides good documentation here:

[url removed, login to view]

Here's the working PHP/CURL function:


function SSLPost($url, $postData){

$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, $url);


curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');

curl_setopt ($ch, CURLOPT_TIMEOUT, 20);

curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,1);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);

curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postData);

curl_setopt ($ch, CURLOPT_POST, 1);

$result = curl_exec($ch);



Here's what I've got so far in Delphi/WinInet (not working):


function SSLPost(url, postData: string): string;


hSession, hConnect, hRequest: HInternet;

Buffer: Array[0..Pred(1024)] of Byte;

BufferLength: DWORD;

stream: TStringStream;

AcceptType: LPStr;

domain, path, header: string;


header:= 'Content-Type: application/x-www-form-urlencoded';

AcceptType := PChar('*/*');

stream:= [url removed, login to view]('');


hSession := InternetOpen('Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)', PRE_CONFIG_INTERNET_ACCESS, nil,nil,0);

if assigned(hSession) then try

hConnect:= InternetConnect(hSession,PChar(domain),443,nil,nil,INTERNET_SERVICE_HTTP,0,0);

if assigned(hConnect) then try

hRequest:= HttpOpenRequest(hConnect,'POST',PChar(path),nil,nil,@AcceptType,INTERNET_FLAG_RELOAD,0);

HttpSendRequest(hRequest, pchar(header), length(header), pchar(postData), length(postData));

if assigned(hRequest) then try

if (extractHeaderCode(hRequest)=200) then begin


InternetReadFile(hRequest, @Buffer, 1024, BufferLength);

[url removed, login to view](Buffer, BufferLength);

until BufferLength = 0;

Result:= [url removed, login to view];


finally InternetCloseHandle(hRequest); end

finally InternetCloseHandle(hConnect); end;

finally InternetCloseHandle(hSession); end;

finally [url removed, login to view]; end;




Here is the test case: (note: you'll have to replace [username] and [pass] with a real Google Adsense account login)

The returned result should be a comma-delimited table. If you get the login page back then the function is not following the login or cookies are not being delt with correctly.


[url removed, login to view]



That's it, I just need one procedure translated and I'm halfway there already.

Kemahiran: Pengaturcaraan C, Delphi, PHP, Destop Windows

Lihat lagi: php function delphi, delphi translate url, httpopenrequest delphi, delphi function, delphi internetopen cookies, delphi curlopt_cookiefile, translate google com, string library in c, string library c, php function for, php create table, pay php, nt job, m string, login page create in php, job nt, job in nt, i need google translate, get length of string in c, create table php, curl_exec delphi, httpsendrequest url delphi, curlopt_post httpsendrequest, curl_close delphi, delphi wininet httpsendrequest

Tentang Majikan:
( 0 ulasan ) Granite bay, United States

ID Projek: #93975