Read this http://en.wikichip.org/wiki/mirc/commands/sockread
Using sockread -f is wrong if you want to read line by line.
%id is not set in your code and just don't use $pos.

Set a bool value to 0, indicating you didn't read the header and set it to 1 when you read the header, you're done reading the header when you are reading line by line and the bool value is 0 and the variable's content is $null.
It's a good idea to use the socket mark as a bool value but here I'm going to use a global variable:

Code:
on *:sockopen:checkName:{
if ($sockerr) { echo -a socket error | return }
sockwrite -n checkName GET ...
sockwrite -n checName Host: ...
set %bool 0
}
on *:sockread:checkName:{
  var %headerfile = $sockname $+ .header.txt,%datafile = $sockname $+ .data.txt
  
  if (!%bool) {
    var %readname  
    sockread %readname
    if (!$sockbr) return
    if (%readname == $null) set %bool 1
    else write %headerfile %readname
  }
  else {
   ;I seperate the read of the header and the rest because you could be willing to read line by line after the header, but into a binvar, which I demonstrate here
   sockread -n &a
   if (!$sockbr) return
   bwrite %datafile -1 -1 &a
  }
}
and now that's a proper event.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel