The GiG
The GiG

Reputation: 2611

Zend HTTP Client password

Im trying to connect from PHP(Zend Framework) code to an aspx Web Service. I need to send via post a few parameters to the page( email, password). I have tried to use Zend_Http_Client, and do this:

$client = new Zend_Http_Client('https://thesiteurl.asmx/Login');
$client->setMethod(Zend_Http_Client::POST);
$client->setAuth($username, $password);
$client->setParameterPost(array('email' => 'email', 'password' => 'password'));
$response = $client->request();
$this->view->response = $response;

where $username, $password are the username and password I use to log in to the web service(it has a pop-up window that asks me for username and password).

This code gives me the unauthorized page. So im asking where am I using the site username and password wrong? How can I use them?

edit: The Auth is auth-basic.

Edit2:

I talked to the owner of the web service he says that everything is UTF-8 is this a problem, isnt it is a default? If not how do i do that?

Upvotes: 6

Views: 3411

Answers (5)

mvds
mvds

Reputation: 47034

The best way to tackle these things is by just using the packet sniffer (tcpdump, ethereal, ...) to see what's happening on the line. Then compare the request/response you observe in a working scenario (e.g. from your browser) to the request/reponse which is not working.

This will very quickly reveal the precise difference at the HTTP level. Using this information you can either find out what to fix in your handling of Zend_Http_Client, or find out that Zend_Http_Client doesn't support a particular feature or authentication scheme.

Upvotes: 0

Marek
Marek

Reputation: 7433

If you can access the servis using browser, use firebug to check the request and response. There might be some other parameters involved, eg cookie.

Upvotes: 0

sharpner
sharpner

Reputation: 3937

have you tried this?

$config = array(
    'adapter'      => 'Zend_Http_Client_Adapter_Socket',
    'ssltransport' => 'tls'
);

$client = new Zend_Http_Client('https://thesiteurl.asmx/Login', $config);
$client->setAuth('shahar', 'myPassword!', Zend_Http_Client::AUTH_BASIC);

also I am confused, is this popup a http basic auth, or something that is self designed? since for basic auth you normally wouldn't send any post params...

the real URL of the site would help very much for finding the solution...

Upvotes: 0

Garuda
Garuda

Reputation: 374

You could check if a referer-header is needed, or it might be that it also needs a cross-site request forgery number. Simply dump the request that is made by your browser when you login and dump the request that your script is generating, compare those and it should work out.

For the browser-request dump you could use livehttpheaders plugin for firefox.

Upvotes: 4

Elzo Valugi
Elzo Valugi

Reputation: 27856

Depends on what that pop up box really is.

You probably need to study the HTTP Authentication. Currently, Zend_Http_Client only supports basic HTTP authentication. This feature is utilized using the setAuth() method, or by specifying a username and a password in the URI. The setAuth() method takes 3 parameters: The user name, the password and an optional authentication type parameter. As mentioned, currently only basic authentication is supported (digest authentication support is planned).

// Using basic authentication
$client->setAuth('shahar', 'myPassword!', Zend_Http_Client::AUTH_BASIC);

// Since basic auth is default, you can just do this:
$client->setAuth('shahar', 'myPassword!');

// You can also specify username and password in the URI
$client->setUri('http://christer:[email protected]');

Source.

If this is not an HTTP auth and is somothing else, try to use cURL, wget or linx to see exactly what is happening on the page and now you can simulate it using Zend_Http_Client. Sometimes you have to send cookies, execute some Js or follow some redirects. Zend_Http_client can do all this things.

Upvotes: 0

Related Questions