Lukket

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_SSL_VERIFYPEER, FALSE);

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);

curl_close($ch);

}

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

============================================================

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

var

hSession, hConnect, hRequest: HInternet;

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

BufferLength: DWORD;

stream: TStringStream;

AcceptType: LPStr;

domain, path, header: string;

begin

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

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

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

try

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

repeat

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

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

until BufferLength = 0;

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

end;

finally InternetCloseHandle(hRequest); end

finally InternetCloseHandle(hConnect); end;

finally InternetCloseHandle(hSession); end;

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

end;

TEST CASE:

==========

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:

[url removed, login to view]

pageData:

destination=/adsense/report/aggregate?sortColumn=0&reverseSort=false&outputFormat=TSV_EXCEL&product=afc&dateRange.simpleDate=today&dateRange.dateRangeType=custom&dateRange.customDate.start.day=23&dateRange.customDate.start.month=8&dateRange.customDate.start.year=2006&dateRange.customDate.end.day=22&dateRange.customDate.end.month=9&dateRange.customDate.end.year=2006&unitPref=page&reportType=property&searchField=&groupByPref=date&username=[username]&password=[pass]&null=Login

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

Færdigheder: C programmering, Delphi, PHP, Windows Skrivebord

Se mere: php function delphi, delphi translate url, delphi function, delphi internetopen cookies, string library, php create table, pay php, nt job, m string, login page create php, job nt, need google translate, get length string, create table php, type cookies, translate a, php create function, translate google get, translate get, translate free, real translate job, get php, translate s, stream api, repeat

Om arbejdsgiveren:
( 0 bedømmelser ) Granite bay, United States

Projekt-ID: #93975