Jump to content

WinHTTP functions


trancexx
 Share

Recommended Posts

Hello

I can set the WinHTTP proxy settings using _WinHttpSetDefaultProxyConfiguration($WINHTTP_ACCESS_TYPE_NAMED_PROXY, $sProxyName, $sProxyBypass) - this is the same as the netsh command "netsh winhttp set proxy ..."

However, I can't find a way to programmatically reset the proxy (ie set NO proxy) - the netsh command is "netsh winhttp reset proxy".

I have tried _WinHttpSetDefaultProxyConfiguration($WINHTTP_ACCESS_TYPE_NO_PROXY, "", "") and _WinHttpSetDefaultProxyConfiguration($WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, "", "") but it always fails with error: "The parameter is incorrect."

I have looked everywhere for one example of how to set "no proxy" using the winhttp api, but I can only find examples of how to set "a proxy".

Any ideas?

Thanks!

Cheers

Toby

Link to comment
Share on other sites

Hello

I recently posted asking about the _WinHttpSetDefaultProxyConfiguration function.

I didn't receive any replies, so I assume no one knows the answer. But just in case I wasn't clear in my question, I thought I'd try again with a related question... (sorry to be kinda posting twice)

Can someone please tell me what the acceptable/correct parameters are for the _WinHttpSetDefaultProxyConfiguration function, as I keep getting the error: "The parameter is incorrect."

Thanks.

Link to comment
Share on other sites

Hello

I recently posted asking about the _WinHttpSetDefaultProxyConfiguration function.

I didn't receive any replies, so I assume no one knows the answer. But just in case I wasn't clear in my question, I thought I'd try again with a related question... (sorry to be kinda posting twice)

Can someone please tell me what the acceptable/correct parameters are for the _WinHttpSetDefaultProxyConfiguration function, as I keep getting the error: "The parameter is incorrect."

Thanks.

It's my fault. I haven't anticipated all possible scenarios for calling that function. That's why there is no example for it in the help file.

To reset proxy call that function like this:

_WinHttpSetDefaultProxyConfiguration($WINHTTP_ACCESS_TYPE_NO_PROXY)

But not until you replace it with this function:

Func _WinHttpSetDefaultProxyConfiguration($iAccessType, $sProxy = "", $sProxyBypass = "")
    Local $tProxy = DllStructCreate("wchar[" & StringLen($sProxy) + 1 & "]")
    DllStructSetData($tProxy, 1, $sProxy)
    Local $tProxyBypass = DllStructCreate("wchar[" & StringLen($sProxyBypass) + 1 & "]")
    DllStructSetData($tProxyBypass, 1, $sProxyBypass)
    Local $tWINHTTP_PROXY_INFO = DllStructCreate("dword AccessType;" & _
            "ptr Proxy;" & _
            "ptr ProxyBypass")
    DllStructSetData($tWINHTTP_PROXY_INFO, "AccessType", $iAccessType)
    If $iAccessType <> $WINHTTP_ACCESS_TYPE_NO_PROXY Then
        DllStructSetData($tWINHTTP_PROXY_INFO, "Proxy", DllStructGetPtr($tProxy))
        DllStructSetData($tWINHTTP_PROXY_INFO, "ProxyBypass", DllStructGetPtr($tProxyBypass))
    EndIf
    Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpSetDefaultProxyConfiguration", "ptr", DllStructGetPtr($tWINHTTP_PROXY_INFO))
    If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
    Return 1
EndFunc
Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • 2 weeks later...

OK so I am able to use an HTTP Proxy ok with this UDF, but now i'm having a problem with the "Proxy-Connection: Close"

How do I change it to "Proxy-Connection: Keep-Alive"..?

I tried setting it in the request headers but that doesn't seem to work for some reason, is there some other way of doing it to keep the proxy connection alive..?

Link to comment
Share on other sites

hi :x my script looks like this:

#include "WinHttp.au3"  
Global Const $sAddress = "dbq.dk"
$1 = (@scriptdir & "\1.txt")
Global $hOpen = _WinHttpOpen()
Global $hConnect = _WinHttpConnect($hOpen, $sAddress)
Global $sHTM = _WinHttpSimpleFormFill($hConnect, Default, Default, "name:ufile", $1) ;upload 1
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

it only works with no subdomain :S.

so if i create a new folder on dbq.dk called: dbq.dk/test and put my php script inside the test folder, and make the script with this:

Global Const $sAddress = "dbq.dk/test" it won't work :/, can someone help me :P?

Link to comment
Share on other sites

hi :x my script looks like this:

#include "WinHttp.au3"  
Global Const $sAddress = "dbq.dk"
$1 = (@scriptdir & "\1.txt")
Global $hOpen = _WinHttpOpen()
Global $hConnect = _WinHttpConnect($hOpen, $sAddress)
Global $sHTM = _WinHttpSimpleFormFill($hConnect, Default, Default, "name:ufile", $1) ;upload 1
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

it only works with no subdomain :S.

so if i create a new folder on dbq.dk called: dbq.dk/test and put my php script inside the test folder, and make the script with this:

Global Const $sAddress = "dbq.dk/test" it won't work :/, can someone help me :P?

Of course it won't work. Read the documentation for that function (parameters). Link for your convenience.

@cypher175, show me the code.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Im pretty sure it was the remote server that was closing the "Proxy-Connection: Keep-Alive" setting, because I tried the same proxy in FireFox on the same remote server and the HTTP Headers were the same, the remote server closed the proxy connection after it was established even though firefox's "proxy-keep-alive" settings were set to true..

Is there anyway to use SOCKS5 Proxies with this WinHTTP UDF or are HTTP Proxies only supported..?

Link to comment
Share on other sites

i tryed using the helpfile, i can't get it to work using a subdomain :/

Ok, thank you for sharing that information.

Find some AutoIt wiki tutorial for beginners. When you learn the basics you will have no problem with this.

I believe Melba23 (he's around) have useful links in his sig.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...