![]() HTTP Status Codes |
![]() ![]() ![]() |
WinHTTP component.
|
type
|
TWinHTTPErrorEvent = procedure(Sender: TObject;
|
ErrorCode: Integer; Stream: TStream) of object;
|
|
property OnHTTPError: TWinHTTPErrorEvent;
|
The OnHTTPError event occurs if some error code has received in the header of response from HTTP server.
|
|
ErrorCode parameter contains the number which identifies the HTTP error (see the list of HTTP Status Codes to recognize an error).
|
|
Stream contains the error page generated by server.
|
|
![]() |
|
![]() |
|
![]() ![]() |
![]() |
Delphi:
|
procedure TForm1.WinHTTP1HTTPError(Sender: TObject;
|
ErrorCode: Integer; Stream: TStream);
|
var
|
Str: String;
|
begin
|
with Stream as TMemoryStream do
|
if OutToMemo1.Checked then
|
begin // Output to Memo1
|
SetLength(Str, Size);
|
Move(Memory^, Str[1], Size);
|
Memo1.Text := Str;
|
end
|
else // Save to file
|
begin
|
Memo1.Text := 'Saved to c:\httptest.dat';
|
SaveToFile('c:\httptest.dat');
|
end;
|
|
case ErrorCode of
|
404: Str := '404: Document not found';
|
500: Str := '500: CGI script failed';
|
else // Mysterious reason
|
Str := IntToStr(ErrorCode);
|
end;
|
|
if (ErrorCode = HTTP_STATUS_OK) or (ErrorCode = HTTP_STATUS_PARTIAL_CONTENT) then // consts from WinInet.pas
|
begin
|
ContinueDownload := False;
|
Exit;
|
end;
|
|
StatusBar1.Panels[0].Text := 'HTTP Error #' + Str;
|
end;
|
C++ Builder:
|
void __fastcall TForm1::WinHTTP1HTTPError(TObject *Sender,
|
int ErrorCode, TStream *Stream)
|
{
|
AnsiString Str;
|
|
if (OutToMemo1->Checked) { // Output to Memo1
|
Str.SetLength(Stream->Size);
|
Move(((TMemoryStream*)Stream)->Memory, &Str[1], Stream->Size);
|
Memo1->Text = Str;
|
}else { // Save to file
|
Memo1->Text = "Saved to c:\httptest.dat";
|
((TMemoryStream*)Stream)->SaveToFile("c:\httptest.dat");
|
}
|
|
switch (ErrorCode) {
|
case 404: Str = "404: Document not found";
|
case 500: Str = "500: CGI script failed";
|
default: Str = IntToStr(ErrorCode); // Mysterious reason
|
};
|
|
StatusBar1->Panels->Items[0]->Text = "HTTP Error #" + Str;
|
}
|
HTTP Status Codes
|
OnHeaderInfo, OnPasswordRequest, OnAnyError and OnDone events.
|