Hi,

I've some problems with my HTTP connection script. Maybe someone can help. I've got no problems when downloading a normal html file. But _calling_ a php file results in a html file messed up with a lot of "random" numbers (e.g. ed0, 85d, 869).
This script should read and post our clan wars into the channel, directly read from our war planer php file. "GetWarsReadVars" & "GetWarsUnsetVars" are usually used to read out my config file. Try:
set %GetWarsHost forums.mirc.com
set %GetWarsPort 80
set %GetWarsFilePath /ubbthreads.php
and:
set %GetWarsHost www.mirc.com
set %GetWarsPort 80
set %GetWarsFilePath /news.html

U'll see the difference. I really don't know why i'm getting such mess and how to avoid it.
Thanks in advance.

@ATMA: Maybe u can learn something from ... laugh

Code:
alias GetWarsReadVars {
  set %GetWarsHost forums.mirc.com
  set %GetWarsPort 80
  set %GetWarsFilePath /ubbthreads.php
  set %GetWarsProtocol HTTP/1.1
  set %GetWarsAuthType None
  set %GetWarsAuthName None
  set %GetWarsAuthPass None
  set %GetWarsLocalFile Forum.html
}

alias GetWarsUnsetVars {
  unset %GetWarsHost
  unset %GetWarsPort
  unset %GetWarsFilePath
  unset %GetWarsProtocol
  unset %GetWarsAuthType
  unset %GetWarsAuthName
  unset %GetWarsAuthPass
  unset %GetWarsLocalFile
}

alias GetWarsTransfer {
  GetWarsReadVars
  if (%GetWarsActive == $null) {
    echo -s *** Clan Wars Info Transfer STARTED! ***
    set %GetWarsActive 1
    set %GetWarsErrors 0
    sockopen GetWarsSock %GetWarsHost %GetWarsPort
  }
  else {
    echo -s *** Clan Wars Info Transfer ACTIVE! ***
  }
}

alias GetWarsErrChk {
  if (*HTTP/* 400* iswm %DL.Header.GetWarsSock) {
    if (%GetWarsHost isin %GetWarsFilePath) {
      set %GetWarsErrors 400001
    }
    else {
      set %GetWarsErrors 400000
    }
  }
  elseif (*HTTP/* 401* iswm %DL.Header.GetWarsSock) {
    if (%GetWarsAuthType == None) {
      set %GetWarsErrors 401001
    }
    elseif (%GetWarsAuthName == $null || %GetWarsAuthPass == $null) {
      set %GetWarsErrors 401002
    }
    else {
      set %GetWarsErrors 401000
    }
  }
  elseif (*HTTP/* 404* iswm %DL.Header.GetWarsSock) {
    set %GetWarsErrors 404000
  }
}

on *:sockopen:GetWarsSock:{
  if ($sockerr > 0) {
    GetWarsUnsetVars
    unset %GetWarsActive
    unset %GetWarsErrors
    echo -s *** ERROR: Remote Host Does NOT RESPOND! ***
    echo -s *** Clan Wars Info Transfer ABORTED! ***
    return
  }
  sockwrite -n GetWarsSock GET %GetWarsFilePath %GetWarsProtocol
  sockwrite -n GetWarsSock Host: %GetWarsHost
  sockwrite -n GetWarsSock Connection: keep-alive
  if (%GetWarsAuthType == Basic) {
    sockwrite -n GetWarsSock Authorization: %GetWarsAuthType $encode(%GetWarsAuthName $+ : $+ %GetWarsAuthPass,mt)
  }
  sockwrite GetWarsSock $crlf
}

on *:SOCKREAD:GetWarsSock:{
  if ($sockerr > 0) {
    GetWarsUnsetVars
    unset %GetWarsActive
    unset %GetWarsErrors
    echo -s *** ERROR: Remote Host Does NOT RESPOND! ***
    echo -s *** Clan Wars Info Transfer ABORTED! ***
    return
  }
  if (%DL.Check.GetWarsSock == $null) {
    sockread %DL.Header.GetWarsSock
    if (%DL.Header.GetWarsSock) {
      echo -s %DL.Header.GetWarsSock
    }
    GetWarsErrChk
    if ($gettok(%DL.Header.GetWarsSock,1,32) == Content-Length:) {
      sockmark GetWarsSock $gettok(%DL.Header.GetWarsSock,2,32)
    }
    if ($len(%DL.Header.GetWarsSock) < 4) {
      if ($sock(GetWarsSock).mark == $null) {
        sockmark GetWarsSock Unknown
      }
      set %DL.Check.GetWarsSock 1
    }
    halt
  }
  if (%GetWarsErrors != 0) { return }
  :start
  sockread &DL.File.GetWarsSock
  if ($sockbr == 0) { return }
  bwrite %GetWarsLocalFile -1 &DL.File.GetWarsSock
  goto start
}

on *:SOCKCLOSE:GetWarsSock:{
  unset %DL.Header.GetWarsSock
  unset %DL.Check.GetWarsSock
  GetWarsUnsetVars
  unset %GetWarsActive
  if (%GetWarsErrors != 0) {
    if (%GetWarsErrors == 400000) {
      echo -s *** ERROR: Bad Request! Check Remote File Location! ***
    }
    if (%GetWarsErrors == 400001) {
      echo -s *** ERROR: Bad Request! Host Must Not Be Included In Remote File Location! ***
    }
    elseif (%GetWarsErrors == 401000) {
      echo -s *** ERROR: HTTP Authorization Failed! Check UserID And Password! ***
    }
    elseif (%GetWarsErrors == 401001) {
      echo -s *** ERROR: HTTP Client Authorization Must Be Enabled! ***
    }
    elseif (%GetWarsErrors == 401002) {
      echo -s *** ERROR: HTTP Authorization UserID AND Password Must Be Given! ***
    }
    elseif (%GetWarsErrors == 404000) {
      echo -s *** ERROR: File Not Found! Check Remote File Location! ***
    }
    else {
      echo -s *** ERROR: Unknown Connection Error! ***
    }
    echo -s *** Clan Wars Info Transfer ABORTED! ***
  }
  else {
    echo -s *** Clan Wars Info Transfer FINISHED! ***
  }
  unset %GetWarsErrors
}