For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > March 2006 > del.icio.us & PHP









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author del.icio.us & PHP
BlueTide

2006-03-07, 3:55 am

Hi,

I'm trying to create a php-page that sits on an intranet server and
goes to fetch my del.icio.us bookmarks to my interface. There are some
complicating factors, first is that the server resides behind an
http-proxy. Second one is that I can't get the http-authentication to
work.

I've gotten through the proxy, and I think my problem is now how to add
headers to my request. In code below I try that. Also, I understood
that the url request needs to be send twice; first the server replies
with authentication request an then we add the headers to answer to it.
Below we send the url on line 3. I also tried to duplicate the line 3
under the line 5. For obvious reasons the usernames, proxy names and
passwords are either changed or not shown at all.

1 $url =
"http://username:password@del.icio.us/api/posts/recent?count=5";

2 $fp = fsockopen($proxy, $port, $errno, $errstr, 1);
3 fputs($fp, "GET $url HTTP/1.0\r\nHost: $proxy\r\n\r\n");
4 fputs($fp, "Authorization: Basic " . base64_encode
("username:password") . "\r\n\r\n");
5 fputs($fp, "User-Agent: SomethingIDefined \r\n\r\n");

6 while ( !feof($fp) ) {
7 $line .= fgets($fp, 9000);
8 }

echo $line;

I have some concerns that I am not using the proxy correctly and the
headers never get to the actual server. The environment is PHP 4.3.2. I
would appreciate all help.

d

2006-03-07, 9:55 pm

"BlueTide" <jpkaasal@yahoo.com> wrote in message
news:1141715447.887891.295520@i39g2000cwa.googlegroups.com...
> Hi,
>
> I'm trying to create a php-page that sits on an intranet server and
> goes to fetch my del.icio.us bookmarks to my interface. There are some
> complicating factors, first is that the server resides behind an
> http-proxy. Second one is that I can't get the http-authentication to
> work.
>
> I've gotten through the proxy, and I think my problem is now how to add
> headers to my request. In code below I try that. Also, I understood
> that the url request needs to be send twice; first the server replies
> with authentication request an then we add the headers to answer to it.
> Below we send the url on line 3. I also tried to duplicate the line 3
> under the line 5. For obvious reasons the usernames, proxy names and
> passwords are either changed or not shown at all.
>
> 1 $url =
> "http://username:password@del.icio.us/api/posts/recent?count=5";
>
> 2 $fp = fsockopen($proxy, $port, $errno, $errstr, 1);
> 3 fputs($fp, "GET $url HTTP/1.0\r\nHost: $proxy\r\n\r\n");
> 4 fputs($fp, "Authorization: Basic " . base64_encode
> ("username:password") . "\r\n\r\n");
> 5 fputs($fp, "User-Agent: SomethingIDefined \r\n\r\n");


You should be using \r\n not \r\n\r\n to seperate your headers. If you use
a double nl/cr, you're just adding lines to the request body, which will be
stripped by the proxy, or ignored by the del.icio.us host. Apart from that,
it looks pretty good ;)

You could use curl to make it easier, but I'd suggest getting to grips with
HTTP as much as possible, as it's good to get the experience ;)

> 6 while ( !feof($fp) ) {
> 7 $line .= fgets($fp, 9000);
> 8 }
>
> echo $line;
>
> I have some concerns that I am not using the proxy correctly and the
> headers never get to the actual server. The environment is PHP 4.3.2. I
> would appreciate all help.


good luck!

dave


BlueTide

2006-03-14, 7:55 am

Thanks, I changed the line endings but other than that have been a
little busy with more acute problems to look at this into detail. But
it is just not working, something odd perhaps in the server. I should
try to have it run on a poxyless webserver soon, but we'll see. Many
irons in the fire at the moment.

Any ideas are always welcomed. The above code returned 404 from
del.icio.us time and again. Now it just hangs. Last one is definitely
because of our server.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com