Sign in to follow this  
Followers 0
Luigi

doubt about WinHttpRequest => SetCredentials

1 post in this topic

#1 ·  Posted (edited)

Greetings!

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)

    $oHTTP.Send($func)

    $oHTTP.WaitForResponse()
    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)
EndFunc

My PHP is...

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

if( isset( $_SERVER['PHP_AUTH_PW'] ) ){
  echo "pass[ {$_SERVER['PHP_AUTH_PW']} ]\n";
}else{
  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?

 

Notes:
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



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  
Followers 0