|
Posted by C. on 08/13/07 12:05
On 12 Aug, 16:34, "Stefano" <o...@interfree.it> wrote:
> I have to send a restart command to an IP camera from a PHP script. The
> command is as follow:
>
> http://192.168.1.5/axis-cgi/admin/restart.cgi
<snip>
> $usarname="root";
> $password="password_root";
> $sk=fsockopen($host,$port,$errnum,$errstr,$timeout) ;
> if(!is_resource($sk)){
> exit("Connection failed: ".$errnum." ".$errstr) ;}
>
> else{
> $headers = "GET ".$target." HTTP/1.1".$br ;
> $headers.="Accept: */*".$br ;
> $headers.="Accept-Language: it".$br ;
> $headers.="Host: ".$host.$br ;
> $headers.="Authorization: Basic root:password_root".$br.$br;
> fputs($sk,$headers) ;
>
<snip>
> When printing $sk I see the error message
>
> 401 Unauthorized
> You client does not have permission to get URL /axis-cgi/admin/restart.cgi
> from this server
>
Why are you rolling your own HTTP stack? PHP comes with 2 builtin
methods - file wrappers and Curl which are both capable of handling
basic authentication (and ssl).
One reason your code is not working is because you haven't base64
encoded the username and password (and you're sending literals not
variables).
C.
Navigation:
[Reply to this message]
|