I'm trying to have my socket download an image file from a site.

I only get a file which is <100 bytes with content like...

Quote:
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰


Here's my code...

Code:
on *:SOCKOPEN:chansock:{
  sockwrite -n $sockname GET / $+ $gettok(%chan.url,3-,47) HTTP/1.1
  sockwrite -n $sockname Host: %chan.host
  sockwrite -n $sockname Accept: */*
  sockwrite -n $sockname Connection: keep-alive
  sockwrite -n $sockname User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
  sockwrite -n $sockname $crlf
}

on *:SOCKREAD:chansock:{
  if ($sockerr) {
    return
  }
  else {
    var %chan.data
    sockread %chan.data
    while ($sockbr) {
      sockread %chan.data
    }
    sockread -f %chan.data
    if (*404 not found* iswm %chan.data) {
      msg %chan.chan Error: 404
      sockclose chansock
      unset %chan.*
    }
    else {
      bwrite %chan.file -1 -1 %chan.data
      msg %chan.chan Succeed!
      sockclose chansock
      unset %chan.*
    }
  }
}

Last edited by gaui; 16/09/08 11:36 PM.

__________________________
Curiosity killed the cat.