Discussion:
WinInet problems with Proxy?
(too old to reply)
Gohlool
2004-04-25 09:04:29 UTC
Permalink
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
Brian Combs
2004-04-28 16:14:39 UTC
Permalink
Hello
This could be a proxy issue. A 307 status code is temporary redirect which
is like a 302 redirect. You can use the debug version of WinInet to see
what is happening.

WinInet Debug
You can download debug builds of WinInet.Dll from the following location:
ftp://ftp.microsoft.com/PSS/Tools/Developer%20Support%20Tools/WinInet/
You should use the build number that is closest to the version of WinInet
that is on your system.

On Win ME/ Windows 2000/ Windows XP and greater OSs with Windows File
Protection

1. Configure Internet Explorer to use a default Start Page as close to the
page as possible. This eliminates much unnecessary logging that will add
additional size to the output log.
2. Close Internet Explorer as well as any other Internet-based applications
(additional applications that use WININET for connectivity may generate
extra traffic within the log).
3. Navigate to the location of where Internet Explorer is installed.
Typically this is either the \Program Files\Internet Explorer folder or the
\Program Files\Plus!\Microsoft Internet folder.
4. You must have extensions viewable so that the proper extension is
assigned to your file. You can turn on the extensions for all files by
going into the Folder Options from within Windows Explorer and choosing the
View tab and selecting to ‘Show all files’ and to not “Hide extensions of
known file types”.
5. Create a dummy file out of a new text file. Rename the file to the
following filename and extension:

IEXPLORE.EXE.LOCAL

The proper extension for this file is .local If you create this file and
you still have a Notepad icon for the file, re-do step 4 above.
6. Once the file has been created successfully, copy a suitable logging
version of WININET.DLL into the same directory as the file you created in
step 5.
7. Once the logging version of WININET is in place, open a CMD prompt.
Navigate to the location of where Internet Explorer is installed.
Typically this is either the \Program Files\Internet Explorer folder or the
\Program Files\Plus!\Microsoft Internet folder.
8. At the CMD prompt, type the following and hit <enter>:

SET WININETLOG=1

9. Now that the logging environment variable is set, you can now start the
logging by typing the following and hitting <enter>:

IEXPLORE.EXE

10. Internet Explorer should now open on the desktop and navigate to the
Start Page. It is important that you do not close either the CMD window or
Internet Explorer. As soon as Internet Explorer starts navigation, a
WININET.LOG file will be created on the desktop. Do not attempt to open
this log while it is being written to.
11. Recreate the problem. Once the behavior is observed, you can now
safely close Internet Explorer, as well as the CMD window. Logging should
cease. The log file should be zipped up and forwarded to a support
professional that has been trained to read these logs. If the log is too
large to send via Microsoft email (5mb), then it must be placed on the
FTPPSS FTP site (ftp://ftppss.microsoft.com)
12. Very Important: once logging is complete, you should remove the
logging version of WININET.DLL and the IEXPLORE.EXE.LOCAL file. Leaving
the logging version of WININET.DLL in place can affect overall browsing
performance because of the numerous checks written into that version.

TIP: For contrast purposes, it would be advisable to have a log of the
problem occurring and one of a normal condition, if possible. Also, a
Network Monitor packet trace that is taken at the same time as the WININET
log may also be beneficial when attempting to correlate network patterns
during the WININET communication.

NOTE: All of Microsoft’s operating systems from Windows 2000 and forward
support the use of IEXPLORE.EXE.LOCAL. This concept is called Dynamic Link
Library Redirection and documented online at http://msdn.microsoft.com.

NOTE: If you are using a custome WinInet application you can replace
IEXPLORE.EXE.LOCAL with your Application file name. And then run your
application from the command prompt.

NOTE: You can change where the log file is saved by setting environment
variable WininetLogFile, like this:
"set wininetlogfile=c:\temp\MyNewLog.log" with out the quotes.

Thanks
Brian [MSFT]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Gohlool" <***@gmx.net>
| Subject: WinInet problems with Proxy?
| Date: Sun, 25 Apr 2004 11:04:29 +0200
| Lines: 97
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <#***@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.inetsdk.programming.wininet
| NNTP-Posting-Host: chello212186029132.406.14.vie.surfer.at 212.186.29.132
| Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12
.phx.gbl
| Xref: cpmsftngxa10.phx.gbl
microsoft.public.inetsdk.programming.wininet:11317
| X-Tomcat-NG: microsoft.public.inetsdk.programming.wininet
|
| 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
|
|
|
Gohlool
2004-04-30 07:47:40 UTC
Permalink
Many many thanks Brian!
I will give a try with the Debug version and see If I can find out what the
problem is!

btw. i found out that as soon as there is no Content-Length in the Header
(in Response from server), the Wininet won't read the Content??

many thanks and best regards,
Gohlool
Post by Brian Combs
Hello
This could be a proxy issue. A 307 status code is temporary redirect which
is like a 302 redirect. You can use the debug version of WinInet to see
what is happening.
WinInet Debug
ftp://ftp.microsoft.com/PSS/Tools/Developer%20Support%20Tools/WinInet/
You should use the build number that is closest to the version of WinInet
that is on your system.
On Win ME/ Windows 2000/ Windows XP and greater OSs with Windows File
Protection
1. Configure Internet Explorer to use a default Start Page as close to the
page as possible. This eliminates much unnecessary logging that will add
additional size to the output log.
2. Close Internet Explorer as well as any other Internet-based
applications
Post by Brian Combs
(additional applications that use WININET for connectivity may generate
extra traffic within the log).
3. Navigate to the location of where Internet Explorer is installed.
Typically this is either the \Program Files\Internet Explorer folder or the
\Program Files\Plus!\Microsoft Internet folder.
4. You must have extensions viewable so that the proper extension is
assigned to your file. You can turn on the extensions for all files by
going into the Folder Options from within Windows Explorer and choosing the
View tab and selecting to 'Show all files' and to not "Hide extensions of
known file types".
5. Create a dummy file out of a new text file. Rename the file to the
IEXPLORE.EXE.LOCAL
The proper extension for this file is .local If you create this file and
you still have a Notepad icon for the file, re-do step 4 above.
6. Once the file has been created successfully, copy a suitable logging
version of WININET.DLL into the same directory as the file you created in
step 5.
7. Once the logging version of WININET is in place, open a CMD prompt.
Navigate to the location of where Internet Explorer is installed.
Typically this is either the \Program Files\Internet Explorer folder or the
\Program Files\Plus!\Microsoft Internet folder.
SET WININETLOG=1
9. Now that the logging environment variable is set, you can now start the
IEXPLORE.EXE
10. Internet Explorer should now open on the desktop and navigate to the
Start Page. It is important that you do not close either the CMD window or
Internet Explorer. As soon as Internet Explorer starts navigation, a
WININET.LOG file will be created on the desktop. Do not attempt to open
this log while it is being written to.
11. Recreate the problem. Once the behavior is observed, you can now
safely close Internet Explorer, as well as the CMD window. Logging should
cease. The log file should be zipped up and forwarded to a support
professional that has been trained to read these logs. If the log is too
large to send via Microsoft email (5mb), then it must be placed on the
FTPPSS FTP site (ftp://ftppss.microsoft.com)
12. Very Important: once logging is complete, you should remove the
logging version of WININET.DLL and the IEXPLORE.EXE.LOCAL file. Leaving
the logging version of WININET.DLL in place can affect overall browsing
performance because of the numerous checks written into that version.
TIP: For contrast purposes, it would be advisable to have a log of the
problem occurring and one of a normal condition, if possible. Also, a
Network Monitor packet trace that is taken at the same time as the WININET
log may also be beneficial when attempting to correlate network patterns
during the WININET communication.
NOTE: All of Microsoft's operating systems from Windows 2000 and forward
support the use of IEXPLORE.EXE.LOCAL. This concept is called Dynamic Link
Library Redirection and documented online at http://msdn.microsoft.com.
NOTE: If you are using a custome WinInet application you can replace
IEXPLORE.EXE.LOCAL with your Application file name. And then run your
application from the command prompt.
NOTE: You can change where the log file is saved by setting environment
"set wininetlogfile=c:\temp\MyNewLog.log" with out the quotes.
Thanks
Brian [MSFT]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| Subject: WinInet problems with Proxy?
| Date: Sun, 25 Apr 2004 11:04:29 +0200
| Lines: 97
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Newsgroups: microsoft.public.inetsdk.programming.wininet
| NNTP-Posting-Host: chello212186029132.406.14.vie.surfer.at
212.186.29.132
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12
Post by Brian Combs
phx.gbl
| Xref: cpmsftngxa10.phx.gbl
microsoft.public.inetsdk.programming.wininet:11317
| X-Tomcat-NG: microsoft.public.inetsdk.programming.wininet
|
| Hi everyone!
|
| I ma using WinInet to post Data to a Web server and receive the
| response with InternetReadFile() function!
|
|
| 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,
| 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
|
| dwBytesRead := 4;
| dwReserved := 0;
| conlen := 0;
| HttpQueryInfo(hPostRequest, HTTP_QUERY_CONTENT_LENGTH or
|
| repeat
| Setlength(Buffer, _buf);
| FillChar(buffer[1], _buf, #0);
| dwBytesRead := 0;
| 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
|
|
|
Continue reading on narkive:
Loading...