Jump to content
Sign in to follow this  

doubt about WinHttpRequest => SetCredentials

Recommended Posts



I have a little AutoIt script and try authenticate in my PHP aplication, like this:

Global $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
Global $REMOTE_URL = "http://localhost/index.php"
Global $REMOTE_USER = "user", $REMOTE_PASS = "pass"

Func Post($func = "")
    $oHTTP.Open("POST", $REMOTE_URL, False)
;~  dXNlcjpwYXNz = base64( "user:pass" )
    $oHTTP.SetRequestHeader("Authorization", "Basic dXNlcjpwYXNz")

    $oHTTP.SetCredentials($REMOTE_USER, $REMOTE_PASS, 0)


    Local $oAllHeaders = $oHTTP.GetAllResponseHeaders()
    ConsoleWrite("+HEADERS=================================" & @LF)
    ConsoleWrite($oAllHeaders & @LF)
    ConsoleWrite("-HEADERS=================================" & @LF)

    Local $oo = $oHTTP.ResponseText
    ConsoleWrite("+RESPONSE================================" & @LF)
    ConsoleWrite($oo & @LF)
    ConsoleWrite("-RESPONSE================================" & @LF)

My PHP is...

if( isset( $_SERVER['PHP_AUTH_USER'] ) ){
  echo "user[ {$_SERVER['PHP_AUTH_USER']} ]\n";
  echo "user[ not exist ]\n";

if( isset( $_SERVER['PHP_AUTH_PW'] ) ){
  echo "pass[ {$_SERVER['PHP_AUTH_PW']} ]\n";
  echo "pass[ not exist ]\n";

If I use $oHTTP.SetCredentials($REMOTE_USER, $REMOTE_PASS, 0) none user/pass is found.

If I use $oHTTP.SetRequestHeader("Authorization", "Basic dXNlcjpwYXNz"), I have user/pass.

I thought that SetCredentials turned the user/pass into Autorizathion Basic dXNlcjpwYXNz, but I see that it does not.

I see that SetCredentials is not seen by PHP.

Where is my error?
Is it possible to do that?


Internet Explorer does not support user names and passwords in Web site addresses (HTTP or HTTPS URLs).

Best regards


Edited by Luigi

Visit my repository

Share this post

Link to post
Share on other sites

Your code not work with port diferent. 
for example I have port 6448. and not Work. Say Error:



Share this post

Link to post
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
Sign in to follow this