Gohlool
2004-04-25 09:04:29 UTC
Hi everyone!
I ma using WinInet to post Data to a Web server and receive the
response with InternetReadFile() function!
Now this are my steps:
dwAccessType := INTERNET_OPEN_TYPE_PRECONFIG; //INTERNET_CONNECTION_PROXY;
dwServerPort := INTERNET_DEFAULT_HTTP_PORT;
dwFlags := INTERNET_FLAG_NO_AUTO_REDIRECT or
INTERNET_FLAG_NO_COOKIES or
INTERNET_FLAG_KEEP_CONNECTION or
INTERNET_FLAG_RELOAD or
INTERNET_FLAG_NO_CACHE_WRITE or
INTERNET_FLAG_DONT_CACHE or
INTERNET_FLAG_PRAGMA_NOCACHE or
INTERNET_FLAG_IGNORE_CERT_CN_INVALID or
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID;
hSession := InternetOpen(nil, dwAccessType, nil, nil, 0);
hConnection := InternetConnect(hSession, Pchar(ServerName),
dwServerPort, nil, nil,
INTERNET_SERVICE_HTTP, 0, 0);
hPostRequest := HttpOpenRequest(hConnection, 'POST', Pchar(RequestObject),
'HTTP/1.1',
Pchar(ServerName), nil, dwFlags , 0 );
InternetSetOption(hPostRequest, INTERNET_OPTION_READ_BUFFER_SIZE,@_buf,
4);
if HttpSendRequest(hPostRequest, nil, 0, Pchar(PostData),
length(PostData)) then
dwLastError := ERROR_SUCCESS
else
dwLastError := GetLastError;
... (Error Handling)
....
....
dwBytesRead := 4;
dwReserved := 0;
HttpCode := 0;
HttpQueryInfo(hPostRequest, HTTP_QUERY_STATUS_CODE or
HTTP_QUERY_FLAG_NUMBER, @HttpCode, dwBytesRead, dwReserved );
dwBytesRead := 4;
dwReserved := 0;
conlen := 0;
HttpQueryInfo(hPostRequest, HTTP_QUERY_CONTENT_LENGTH or
HTTP_QUERY_FLAG_NUMBER, @conlen, dwBytesRead, dwReserved );
repeat
Setlength(Buffer, _buf);
FillChar(buffer[1], _buf, #0);
dwBytesRead := 0;
if not InternetReadFile(hPostRequest, pointer(@buffer[1]), _buf,
dwBytesRead) then begin
dwError := GetLastError;
Break;
end;
if dwBytesRead > 0 then begin
Setlength(buffer, dwBytesRead);
Result := Result + buffer;
end;// else Sleep(500);
until (dwBytesRead = 0);
InternetCloseHandle(hSession);
InternetCloseHandle(hConnection);
InternetCloseHandle(hPostRequest);
now, I am using this steps to send the data to a web server who response me
with a HTTP Code 307 and send me the content too.
Now if I use the same steps and set in Internet settings to use a
Proxy, I get the same HTTP Header as I used without proxy before but
this time I am not getting the Content sent by server.
So for testing I installed the TCPMon from Axis and run it in Proxy
mode. Set the Internet settings to use this local "proxy".
Then I repeated my test and saw that the server send the data (Content) back
(can see it in TCPMon), but the wininet says there is not data???
so as told you before if I turn the proxy off in Internet settings
(Direct connect) then everything is fine???
dose anybody have any idea how to solve this problem?
TIA
Gohlool
I ma using WinInet to post Data to a Web server and receive the
response with InternetReadFile() function!
Now this are my steps:
dwAccessType := INTERNET_OPEN_TYPE_PRECONFIG; //INTERNET_CONNECTION_PROXY;
dwServerPort := INTERNET_DEFAULT_HTTP_PORT;
dwFlags := INTERNET_FLAG_NO_AUTO_REDIRECT or
INTERNET_FLAG_NO_COOKIES or
INTERNET_FLAG_KEEP_CONNECTION or
INTERNET_FLAG_RELOAD or
INTERNET_FLAG_NO_CACHE_WRITE or
INTERNET_FLAG_DONT_CACHE or
INTERNET_FLAG_PRAGMA_NOCACHE or
INTERNET_FLAG_IGNORE_CERT_CN_INVALID or
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID;
hSession := InternetOpen(nil, dwAccessType, nil, nil, 0);
hConnection := InternetConnect(hSession, Pchar(ServerName),
dwServerPort, nil, nil,
INTERNET_SERVICE_HTTP, 0, 0);
hPostRequest := HttpOpenRequest(hConnection, 'POST', Pchar(RequestObject),
'HTTP/1.1',
Pchar(ServerName), nil, dwFlags , 0 );
InternetSetOption(hPostRequest, INTERNET_OPTION_READ_BUFFER_SIZE,@_buf,
4);
if HttpSendRequest(hPostRequest, nil, 0, Pchar(PostData),
length(PostData)) then
dwLastError := ERROR_SUCCESS
else
dwLastError := GetLastError;
... (Error Handling)
....
....
dwBytesRead := 4;
dwReserved := 0;
HttpCode := 0;
HttpQueryInfo(hPostRequest, HTTP_QUERY_STATUS_CODE or
HTTP_QUERY_FLAG_NUMBER, @HttpCode, dwBytesRead, dwReserved );
dwBytesRead := 4;
dwReserved := 0;
conlen := 0;
HttpQueryInfo(hPostRequest, HTTP_QUERY_CONTENT_LENGTH or
HTTP_QUERY_FLAG_NUMBER, @conlen, dwBytesRead, dwReserved );
repeat
Setlength(Buffer, _buf);
FillChar(buffer[1], _buf, #0);
dwBytesRead := 0;
if not InternetReadFile(hPostRequest, pointer(@buffer[1]), _buf,
dwBytesRead) then begin
dwError := GetLastError;
Break;
end;
if dwBytesRead > 0 then begin
Setlength(buffer, dwBytesRead);
Result := Result + buffer;
end;// else Sleep(500);
until (dwBytesRead = 0);
InternetCloseHandle(hSession);
InternetCloseHandle(hConnection);
InternetCloseHandle(hPostRequest);
now, I am using this steps to send the data to a web server who response me
with a HTTP Code 307 and send me the content too.
Now if I use the same steps and set in Internet settings to use a
Proxy, I get the same HTTP Header as I used without proxy before but
this time I am not getting the Content sent by server.
So for testing I installed the TCPMon from Axis and run it in Proxy
mode. Set the Internet settings to use this local "proxy".
Then I repeated my test and saw that the server send the data (Content) back
(can see it in TCPMon), but the wininet says there is not data???
so as told you before if I turn the proxy off in Internet settings
(Direct connect) then everything is fine???
dose anybody have any idea how to solve this problem?
TIA
Gohlool