Translate one PHP function to Delphi

I need the following PHP/CURL function translated into a Delphi/WinInet function. I'll pay $25, should be pretty easy for anyone familiar with WinInet.

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 [url removed, login to view]; 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 [url removed, login to view]; 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: Delphi, Perl, PHP, Destop Windows

Lihat lebih lanjut: curl translate php delphi, php create table, pay php, m string, login page create php, need google translate, get length string, create table php, translate delphi php, type cookies, php create function, translate google get, translate get, translate free, get php, translate s, repeat, php test, php perl, php adsense, one free, one day, null, nt, nil

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

ID Projek: #92119