mIRC Home    About    Download    Register    News    Help

Print Thread
#173606 26/03/07 06:22 PM
Joined: Mar 2005
Posts: 74
D
defiant Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Mar 2005
Posts: 74
Hi,

I'm trying to retrieve some info from a website, thru sockets. I'm no expert in this, but i do have searched and tried alot of combinations, but i simply can't get it to work.

The goal is, to retrieve only one line, from a page like this:
http://www.clanbase.com/cbrank.php?cid=113892&lid=2398&type=js
(The &type=js is optional).

So far, i've came only to 'debugging', and this is what i came up with:

Code:
 
alias cb.rank {
  if ($sock(cbrank)) { sockclose cbrank }
  sockopen cbrank www.clanbase.com 80
}

on *:sockopen:cbrank:{
sockwrite -t cbrank GET cbrank.php?cid=113892&lid=2398&type=js HTTP/1.0
  sockwrite -n cbrank Host: www.clanbase.com 80
  sockwrite -n cbrank $crlf
}
on *:sockread:cbrank:{
  sockread %vrs
  echo -a :: %vrs
}



And this is what it returns:
Code:
:: HTTP/1.1 400 Bad Request
:: Date: Mon, 26 Mar 2007 18:22:38 GMT
:: Server: Apache/1.3.37 (Unix) PHP/4.4.2
:: Connection: close
:: Content-Type: text/html; charset=iso-8859-1
::
:: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
:: <HTML><HEAD>
:: <TITLE>400 Bad Request</TITLE>
:: </HEAD><BODY>
:: <H1>Bad Request</H1>
:: Your browser sent a request that this server could not understand.<P>
:: The request line contained invalid characters following the protocol string.<P>
:: <P>
:: </BODY></HTML>


I really have no clue what to change, to make it work. While it just should return "document.write(3)" in this case.

defiant #173607 26/03/07 06:34 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
You're using the -t switch instead of the -n switch for the first /sockread line in the sockread event so $crlf isn't being appended. Also you need to prefix the URL with a /
Code:
sockwrite -n cbrank GET /cbrank.php?cid=113892&lid=2398&type=js HTTP/1.0


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Mar 2005
Posts: 74
D
defiant Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Mar 2005
Posts: 74
I've done that too, but the error still occurred, tought i need a -t because of the "&" char. It's working now tho, however... not entirely as expected:

Code:
:: HTTP/1.1 200 OK
:: Date: Mon, 26 Mar 2007 18:50:51 GMT
:: Server: Apache/1.3.37 (Unix) PHP/4.4.2
:: X-Powered-By: PHP/4.4.2
:: Set-Cookie: c=nl; expires=Wed, 25 Apr 2007 18:50:52 GMT; domain=clanbase.com
:: Set-Cookie: PHPSESSID=545645646878987987; path=/
:: Expires: Thu, 19 Nov 1981 08:52:00 GMT
:: Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
:: Pragma: no-cache
:: Connection: close
:: Content-Type: text/html


I suppose that it's asking for a cookie now, before showing me that information ? Easy to 'fix' this?

defiant #173609 26/03/07 06:54 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Yeah you only need the -t switch if the data you're sending begins with a &. Otherwise it doesn't matter.

The problem now is that the webpage you're connecting to doesn't finish the content with a $crlf, so /sockread won't read the data into a text variable unless you force it to with the -f switch:
Code:
on *:sockread:cbrank:{
  while 1 {
    sockread %vrs
    echo -a :: %vrs
    if (!$sockbr) break
  }
  ; All the lines ending with $crlf have been read!

  ; Now we check the read queue to see if there's any data we'll need to force with -f
  if ($sock(cbrank).rq) {
    sockread -f %vrs
    echo -a :: %vrs
  }
}


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Mar 2005
Posts: 74
D
defiant Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Mar 2005
Posts: 74
ah, i see smile It works like a charm now. Thanks alot for your help.


Link Copied to Clipboard