📄 posturlpas.pas
字号:
unit postURLpas;
interface
uses
Windows, Wininet;//, Base;
function PostURL(const aUrl: string;FTPostQuery:String): Boolean;
implementation
function LowerCase(const S: string): string;
var
Ch: Char;
L: Integer;
Source, Dest: PChar;
begin
L := Length(S);
SetLength(Result, L);
Source := Pointer(S);
Dest := Pointer(Result);
while L <> 0 do
begin
Ch := Source^;
if (Ch >= 'A') and (Ch <= 'Z') then Inc(Ch, 32);
Dest^ := Ch;
Inc(Source);
Inc(Dest);
Dec(L);
end;
end;
function PostURL(const aUrl: string;FTPostQuery:String): Boolean;
var
//F2: TextFile;
hSession: HINTERNET;
hConnect, hRequest: hInternet;
lpBuffer: array[0..1024 + 1] of Char;
dwBytesRead: DWORD;
HttpStr:String;
HostName, FileName: String;
FTResult: Boolean;
AcceptType: LPStr;
Buf: Pointer;
dwBufLen, dwIndex: DWord;
procedure ParseURL(URL: String; var HostName, FileName: String);
procedure ReplaceChar(c1, c2: Char; var St: String);
var
p: Integer;
begin
while True do
begin
p := Pos(c1, St);
if p = 0 then Break
else St[p] := c2;
end;
end;
var
i: Integer;
begin
if Pos('http://', LowerCase(URL)) <> 0 then
System.Delete(URL, 1, 7);
i := Pos('/', URL);
HostName := Copy(URL, 1, i);
FileName := Copy(URL, i, Length(URL) - i + 1);
if (Length(HostName) > 0) and (HostName[Length(HostName)] = '/') then
SetLength(HostName, Length(HostName) - 1);
end;
begin
hSession := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
Result := False;
// try
if Assigned(hSession) then
begin
ParseURL(aUrl, HostName, FileName);
hConnect := InternetConnect(hSession, PChar(HostName),
INTERNET_DEFAULT_HTTP_PORT, nil, nil, INTERNET_SERVICE_HTTP, 0, 0);
AcceptType := PChar('Accept: */*');
hRequest := HttpOpenRequest(hConnect, 'POST', PChar(FileName), 'HTTP/1.0',
nil, @AcceptType, INTERNET_FLAG_RELOAD, 0);
//
HttpSendRequest(hRequest, 'Content-Type: application/x-www-form-urlencoded', 47,
PChar(FTPostQuery), Length(FTPostQuery));
dwIndex := 0;
dwBufLen := 1024;
GetMem(Buf, dwBufLen);
FTResult := HttpQueryInfo(hRequest, HTTP_QUERY_CONTENT_LENGTH,
Buf, dwBufLen, dwIndex);
if FTResult=True then
begin
// try
while True do
begin
dwBytesRead := 1024;
InternetReadFile(hRequest, @lpBuffer, 1024, dwBytesRead);
if dwBytesRead = 0 then break;
lpBuffer[dwBytesRead] := #0;
HttpStr:=HttpStr+lpBuffer;
end;
if Pos('成功',HttpStr)>0 then
Result := True;
//else
//Result := False;
//Form1.Memo1.Lines.Add(Httpstr);
{try
AssignFile(F2, 'C:\httpstr.txt');
Rewrite(F2);
Write(F2, Httpstr);
CloseFile(F2);
except
end;}
// finally
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
// end;
end
else
begin
{try
AssignFile(F2, 'C:\httpstr2.txt');
Rewrite(F2);
Write(F2, '没有post');
CloseFile(F2);
except
end;}
end;
end;
// finally
InternetCloseHandle(hSession);
// end;
end;
{function ReadURL(const aUrl: string): Boolean;
var
hSession: HINTERNET;
hService: HINTERNET;
lpBuffer: array[0..1024 + 1] of Char;
dwBytesRead: DWORD;
HttpStr:String;
begin
hSession := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
if Assigned(hSession) then
begin
hService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, INTERNET_FLAG_NO_CACHE_WRITE + INTERNET_FLAG_NO_UI, 0);
if Assigned(hService) then
try
while True do
begin
dwBytesRead := 1024;
InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead);
if dwBytesRead = 0 then break;
lpBuffer[dwBytesRead] := #0;
HttpStr:=HttpStr+lpBuffer;
end;
Result := True;
try
NewVer:=strtoint(CenterStr(HttpStr,'<inf>','</inf>'));
except
NewVer:=1;
end;
DownEXEFiles:=CenterStr(HttpStr,'<down>','</down>');
finally
InternetCloseHandle(hService);
end;
end;
finally
InternetCloseHandle(hSession);
end;
end; }
{procedure UploadThread(Thread: TThread);
var p:Longint; i:integer;
SubKey,ServerName,ZB:string;
ok:boolean;
//LogFile : textfile;
begin
Sleep(5000);
if not PostURL('http://www.tianjianok01.com/mir/login.asp','gameid='+UserName+'&password='+PassWord+'&quyu='+quyu+'&mirserver='+ServerNick+'&js1='+js1name+'&js1zy='+Js1ZhiYe+
'&js1dj='+Js1Dengji+'&js1sex='+Js1Xingbei+'&js2='+Js2Name+'&js2zy='+Js2zhiye+'&js2dj='+js2dengji+'&js2sex='+Js2Xingbei+'&zb='+ZhuangBei) then
begin
end
else
begin
end;
end; }
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -