3
3h
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.GetValue(Year, Month, Day, Hour: Integer; var TripTime,
Lost: Real);
const
INTERNET_FLAG = INTERNET_FLAG_DONT_CACHE or INTERNET_FLAG_NO_AUTO_REDIRECT
or INTERNET_FLAG_PRAGMA_NOCACHE or INTERNET_FLAG_RELOAD
or INTERNET_FLAG_RESYNCHRONIZE or INTERNET_FLAG_KEEP_CONNECTION;
var
URI: String;
H_INET_OPEN, H_INET_CONN, H_HTTP_OPEN: HINTERNET;
I, Index, Len, dwRead: DWORD;
Buf: String;
begin
URI := Format('/',[Year, Month, Day, Hour]);
H_INET_OPEN := InternetOpen('HHH', INTERNET_OPEN_TYPE_DIRECT, Nil, Nil, 0);
H_INET_CONN := InternetConnect(H_INET_OPEN, '1.1.1.1', 80, Nil, Nil,
INTERNET_SERVICE_HTTP, 0, 0);
if H_INET_CONN = Nil then
begin
ShowMessage('连接到服务器失败。');
InternetCloseHandle(H_INET_OPEN);
Exit;
end;
H_HTTP_OPEN := HttpOpenRequest(H_INET_CONN, Nil, PChar(URI),
Nil, Nil, Nil, INTERNET_FLAG, 0);
try
If H_HTTP_OPEN <> Nil then
begin
HttpSendRequest(H_HTTP_OPEN, Nil, 0, Nil, 0);
I := GetLastError;
If I = 0 then
begin
SetLength(Buf, 100);
Len := 100;
Index := 0;
HttpQueryInfo(H_HTTP_OPEN, HTTP_QUERY_CONTENT_LENGTH,
PChar(Buf), Len, Index);
Len := StrToIntDef((Copy(buf, 0, Len)), 0);
SetLength(Buf, Len);
try
dwRead := 1;
If (Len > 0) and InternetReadFile(H_HTTP_OPEN, PChar(Buf), Len, dwRead) then
GetValue(Buf, TripTime, Lost);
finally
Buf := '';
end;
end
else // GetLastError != 0
begin
ShowMessage(GetMessageText(I));
ShowMessage(Format('发生错误在获取%d年%d月%d日%d时的资料时。', [Year, Month, Day, Hour]));
end;
end;
finally
If H_HTTP_OPEN <> Nil then
InternetCloseHandle(H_HTTP_OPEN);
If H_INET_CONN <> Nil then
InternetCloseHandle(H_INET_CONN);
If H_INET_OPEN <> Nil then
InternetCloseHandle(H_INET_OPEN);
end;
end;
----------------------------------
困扰:在GetLastError之后总是提示该服务器不支持该功能。
用IE打开这个页面是没有问题的。GetValue是一个Overload的函数。
事实上我怀疑是页名后参数的问题,就是"?xxxx=DDD&xxx=ssss"这些东东。
不知道正确的用法应该是怎么样的呢?
声明:以上地址均为假地址。
Lost: Real);
const
INTERNET_FLAG = INTERNET_FLAG_DONT_CACHE or INTERNET_FLAG_NO_AUTO_REDIRECT
or INTERNET_FLAG_PRAGMA_NOCACHE or INTERNET_FLAG_RELOAD
or INTERNET_FLAG_RESYNCHRONIZE or INTERNET_FLAG_KEEP_CONNECTION;
var
URI: String;
H_INET_OPEN, H_INET_CONN, H_HTTP_OPEN: HINTERNET;
I, Index, Len, dwRead: DWORD;
Buf: String;
begin
URI := Format('/',[Year, Month, Day, Hour]);
H_INET_OPEN := InternetOpen('HHH', INTERNET_OPEN_TYPE_DIRECT, Nil, Nil, 0);
H_INET_CONN := InternetConnect(H_INET_OPEN, '1.1.1.1', 80, Nil, Nil,
INTERNET_SERVICE_HTTP, 0, 0);
if H_INET_CONN = Nil then
begin
ShowMessage('连接到服务器失败。');
InternetCloseHandle(H_INET_OPEN);
Exit;
end;
H_HTTP_OPEN := HttpOpenRequest(H_INET_CONN, Nil, PChar(URI),
Nil, Nil, Nil, INTERNET_FLAG, 0);
try
If H_HTTP_OPEN <> Nil then
begin
HttpSendRequest(H_HTTP_OPEN, Nil, 0, Nil, 0);
I := GetLastError;
If I = 0 then
begin
SetLength(Buf, 100);
Len := 100;
Index := 0;
HttpQueryInfo(H_HTTP_OPEN, HTTP_QUERY_CONTENT_LENGTH,
PChar(Buf), Len, Index);
Len := StrToIntDef((Copy(buf, 0, Len)), 0);
SetLength(Buf, Len);
try
dwRead := 1;
If (Len > 0) and InternetReadFile(H_HTTP_OPEN, PChar(Buf), Len, dwRead) then
GetValue(Buf, TripTime, Lost);
finally
Buf := '';
end;
end
else // GetLastError != 0
begin
ShowMessage(GetMessageText(I));
ShowMessage(Format('发生错误在获取%d年%d月%d日%d时的资料时。', [Year, Month, Day, Hour]));
end;
end;
finally
If H_HTTP_OPEN <> Nil then
InternetCloseHandle(H_HTTP_OPEN);
If H_INET_CONN <> Nil then
InternetCloseHandle(H_INET_CONN);
If H_INET_OPEN <> Nil then
InternetCloseHandle(H_INET_OPEN);
end;
end;
----------------------------------
困扰:在GetLastError之后总是提示该服务器不支持该功能。
用IE打开这个页面是没有问题的。GetValue是一个Overload的函数。
事实上我怀疑是页名后参数的问题,就是"?xxxx=DDD&xxx=ssss"这些东东。
不知道正确的用法应该是怎么样的呢?
声明:以上地址均为假地址。