Dear Perl Gurus,

I am writing a perl script to download files from internet using perl LWP , WWW::Mechanize modules. Currently I rely on HTTP_PROXY environment variable to understand the proxy. But it is pain to instruct the Windows users to set this variable and use my script.

I am thinking to find the HTTP proxy automatically and i was looking into MSDN and I found following windows APIs,

1. WinHttpGetProxyForUrl , http://msdn.microsoft.com/en-us/library/windows/desktop/aa384097(v=vs.85).aspx

2. InternetGetProxyInfo , http://msdn.microsoft.com/en-us/library/windows/desktop/aa384726(v=vs.85).aspx

I tried to use InternetGetProxyInfo API by using following code but looks like API itself is broken and suggestion is to use WinHttpGetProxyForUrl .

use strict; use warnings; use Win32::Internet; use Win32::API; #$Win32::API::DEBUG = 1; my $InternetGetProxyInfo = Win32::API->new('jsproxy.dll', 'BOOL Intern +etGetProxyInfo(LPCSTR lpszUrl, DWORD dwUrlLength, LPSTR lpszUrlHostNa +me, DWORD dwUrlHostNameLength, LPSTR lplpszProxyHostName, LPDWORD lpd +wProxyHostNameLength)') or warn "\n ERROR: Can not import API:i2cGetD +eviceAddress , $^E ,"; my $lpszUrl = 'http://www.google.com'; my $dwUrlLength = length($lpszUrl); my $lpszUrlHostName = 'www.google.com'; my $dwUrlHostNameLength = length($lpszUrlHostName); my $lplpszProxyHostName = " " x 100; my $lpdwProxyHostNameLength = 0; print $InternetGetProxyInfo->Call($lpszUrl,$dwUrlLength,$lpszUrlHostNa +me,$dwUrlHostNameLength,$lplpszProxyHostName,$lpdwProxyHostNameLength +) or print "\n ERR: ",$^E; print "\n ERR:", Win32::FormatMessage(Win32::GetLastError()); print "\n 1: $lplpszProxyHostName \n 2: $lpdwProxyHostNameLength \n";

Question: Any one tried this API in perl already? If so can you please point me some code reference? Or is there any better way to detect HTTP proxy automatically?

Thanks & Regards,
Bakki

Perl Gtk2 technology demo project - http://code.google.com/p/saaral-soft-search-spider/


In reply to How to Detect HTTP proxy settings automatically in Windows OS? by sam_bakki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.