Delphi Sample Code (GET)
function getURLContent(const Url: string): string;
var
NetHandle: HINTERNET;
UrlHandle: HINTERNET;
Buffer: array[0. .1024] of Char;
BytesRead: dWord;
begin
Result: = '';
NetHandle: = InternetOpen('Delphi 5.x', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(NetHandle) then
begin
UrlHandle: = InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);
if Assigned(UrlHandle) then {
UrlHandle valid ? Proceed with download
}
begin
FillChar(Buffer, SizeOf(Buffer), 0);
repeat
Result: = Result + Buffer;
FillChar(Buffer, SizeOf(Buffer), 0);
InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);
until BytesRead = 0;
InternetCloseHandle(UrlHandle);
end
else {
UrlHandle is not valid.Raise an exception.
}
raise Exception.CreateFmt('Cannot open URL %s', [Url]);
InternetCloseHandle(NetHandle);
end
else {
NetHandle is not valid.Raise an exception
}
raise Exception.Create('Unable to initialize Wininet');
end;
u: = 'https://www.hajanaone.com/api/sendsms.php?' + 'apikey=yourapikey' + '&message=message' + '&sender=sender' + '&phone=923331234567,923001234567,923451234567';
GetUrlContent(u);
Caution: Some use
Delphi Sample Code (POST)
function SendSMS(apiKey, Sender, phone,
message: String):string;
const
URL = 'https://www.hajanaone.com?apikey=%s&sender=%s&phone=%s&message=%s';
ResponseSize = 1024;
var
hSession, hURL: HInternet;
Request: String;
ResponseLength: Cardinal;
begin
hSession := InternetOpen('DrBob42', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
Request := Format(URL,[apiKey,Sender,Numbers,HttpEncode(Message)]);
hURL := InternetOpenURL(hSession, PChar(Request), nil, 0,0,0);
try
SetLength(Result, ResponseSize);
InternetReadFile(hURL, PChar(Result), ResponseSize,
ResponseLength);
SetLength(Result, ResponseLength)
finally
InternetCloseHandle(hURL)
end
finally
InternetCloseHandle(hSession)
end
end;