Find Jobs
Hire Freelancers

Translate a PHP function to Delphi

$30-100 USD

Closed
Posted over 17 years ago

$30-100 USD

Paid on delivery
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: [login to view URL] 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 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); 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:= [login to view URL](''); try 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 repeat InternetReadFile(hRequest, @Buffer, 1024, BufferLength); [login to view URL](Buffer, BufferLength); until BufferLength = 0; Result:= [login to view URL]; end; finally InternetCloseHandle(hRequest); end finally InternetCloseHandle(hConnect); end; finally InternetCloseHandle(hSession); end; finally [login to view URL]; 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: [login to view URL] 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.
Project ID: 93975

About the project

3 proposals
Remote project
Active 17 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs

About the client

Flag of UNITED STATES
Granite bay, United States
0.0
0
Member since Jul 16, 2004

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.