Francois Vermeulen wrote: > I get the "The data area passed to a system call is too small" error on my > HttpOpenRequest call. The program works fine on my local machine but if I > copy it to the server where it should run I get this error. > > fuction doCall( const aUrl : String ) : String; > var > hSession, hHostConnection, hDownload: HINTERNET; > Buffer: PChar; > dwBufLen, dwIndex, dwBytesRead, dwTotalBytes: DWORD; > HasSize: Boolean; > Buf: array [0..1024] of Byte; > l_stream : TStream; > l_strStream : TStringStream; > begin > //open the connection to the internet > hsession := InternetOpen(PChar(''), INTERNET_OPEN_TYPE_DIRECT, nil, nil, > 0); > if hSession = nil then > begin > Result := SysErrorMessage(GetLastError); > Exit; > end; > > // Connect to the host > hHostConnection := InternetConnect(hSession, PChar(aUrl), 0, nil, nil, > INTERNET_SERVICE_HTTP, 0, DWORD(0));
The second parameter is supposed to be a server name or IP address. Maybe that's what you're doing, but the name of the variable you're using suggests you're not providing just the server name. Documentation doesn't say anything about zero being a valid value for the third parameter. If you don't want to specify the port number, then use Internet_Invalid_Port_Number. Or, since you know you're using HTTP, use Internet_Default_HTTP_Port. > if hHostConnection = nil then > begin > Result := 'Error in connection'; > Exit; If you exit here, then you leave the hSession handle open. You should protect it with a try-finally block to call InternetCloseHandle before the function returns. > end; > > //Request the file > hDownload := HttpOpenRequest(hHostConnection, 'GET', PChar(''), > 'HTTP/1.0', > PChar(''), nil, INTERNET_FLAG_RELOAD or INTERNET_FLAG_PRAGMA_NOCACHE, > 0); What is this function supposed to do? You haven't told it what it should request (the third parameter). Also note that an empty string is not the same as null. If you don't want to have a referrer, then you should pass nil, not a pointer to a null character. The type-casting isn't necessary. > if hDownload = nil then > begin > Result := 'Could not download ' + SysErrorMessage(GetLastError); > Exit; If you exit here, then you leave both hSession and hHostConnection open. Use another try-finally block to protect the latter. (The former will already be protected from the previous try-finally block. > end; > > //Send the request > HttpSendRequest(hDownload, nil, 0, nil, 0); Are you really ignoring the return value? -- Rob __________________________________________________ Delphi-Talk mailing list -> Delphi-Talk@elists.org http://www.elists.org/mailman/listinfo/delphi-talk