Что я делаю не так? Данные не возвращаются
function TForm1.PostData(Data: ansiString; const URL: String): String;
var
Server, Path, Extra: String;
Scheme, Port, Flags, Ctx: Integer;
Status, Index, Size, Downloaded: DWord;
FInetRoot, FInetConnect, FInetRequest: HInternet;
Buffer: String;
const
AcceptTypes: array [0..1] of PChar = ('text/xml', nil);
begin
FInetRequest := nil;
FInetConnect := nil;
server := 'dy.cdrrhq.ru';
path := '/';
extra := 's';
scheme := INTERNET_SCHEME_HTTP;
port := INTERNET_DEFAULT_HTTP_PORT;
Ctx := Random(MaxInt);
FInetRoot := InternetOpen( 'h', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
FInetConnect := InternetConnect(FInetRoot, PChar(Server), Port, nil, nil, INTERNET_SERVICE_HTTP, 0, Ctx);
Flags := INTERNET_FLAG_KEEP_CONNECTION or INTERNET_FLAG_NO_CACHE_WRITE;
if Scheme = INTERNET_SCHEME_HTTPS then
Flags := Flags or INTERNET_FLAG_SECURE;
FInetRequest := HttpOpenRequest( FInetConnect, 'POST', PChar(Path + Extra), nil, nil, @AcceptTypes, Flags, Ctx);
HttpSendRequest(FInetRequest, nil, 0, PChar(Data), Length(Data));
Size := SizeOf(Status);
index := 0;
if HttpQueryInfo(FInetRequest, HTTP_QUERY_STATUS_CODE or HTTP_QUERY_FLAG_NUMBER, @Status, Size, index)
and (Status >= 300) then
begin
Size := 1024;
SetLength(Buffer, Size);
if HttpQueryInfo( FInetRequest, HTTP_QUERY_STATUS_TEXT, @Buffer[1], Size, Index) then
begin
SetLength(Buffer, Size);
msgok(Buffer);
Exit;
end;
end;
Result := '';
repeat
InternetQueryDataAvailable( FInetRequest, Size, 0, Ctx);
if Size > 0 then
begin
SetLength(Buffer, Size);
InternetReadFile( FInetRequest, @Buffer[1], Size, Downloaded);
SetLength(Buffer, Downloaded);
Result := Result + Buffer;
end;
until Size = 0;
finally
InternetCloseHandle(FInetRequest);
InternetCloseHandle(FInetConnect);
InternetCloseHandle(FInetRoot);
end;
end;
procedure TForm1.Button1Click(Sender: PObj);
begin
memo1.Text := PostData('n1=1&n2=b&n3=5', '');