mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2024
Posts: 1
G
gbigggs Offline OP
Mostly harmless
OP Offline
Mostly harmless
G
Joined: Dec 2024
Posts: 1
I have a script that is pretty straight forward, open a website with an https socket and copy the output into a file, my problem is, i am getting a 400 error when the socket opens and i need to really copy a line that starts with a string, say TTNM7 to a variable so that it can be processed later.

Code
Alias Demo {
  /remove c:\aprs\ $+ $date(mm) $+ $date(dd) $+ .txt
  sockOpen -e demo mesonet.agron.iastate.edu 443
}

;https://mesonet.agron.iastate.edu/request/coop/obs-dl.php?network=MO_COOP&station%5B%5D=TTNM7&year1= 4+ $date(yyyy) $+ &month1=12&day1=23&year2=2024&month2=12&day2=23&what=view&delim=space

on *:SockOpen:demo: {
  sockwrite -nt demo GET request/coop/obs-dl.php?network=MO_COOP&station%5B%5D=TTNM7&year1= $+ $date(yyyy) $+ &month1= $+ $date(mm) $+ &day1= $+ $date(dd) $+ &year2= $+ $date(yyyy) $+ &month2= $+ $date(mm) $+ &day2= $+ $date(dd) $+ &what=view&delim=space HTTP/1.1
  echo request/coop/obs-dl.php?network=MO_COOP&station%5B%5D=TTNM7&year1= $+ $date(yyyy) $+ &month1= $+ $date(mm) $+ &day1= $+ $date(dd) $+ &year2= $+ $date(yyyy) $+ &month2= $+ $date(mm) $+ &day2= $+ $date(dd) $+ &what=view&delim=space HTTP/1.0
  sockwrite -nt demo Host: 204.48.104.102
  sockwrite -nt demo $crlf
}
on *:SockRead:demo: {
  var %read
  sockRead -t %read
  echo %read
  if (TTNM7 isin %read) { 
    write c:\aprs\ $+ $date(mm) $+ $date(dd) $+ .txt $1-
  }
}
on *:SockClose:demo: {
  set %tx-sec $round($calc(%tx-time / 1000),0)
  set %tx-min $calc(%tx-sec / 60)
  /timerdemo 23:58 1 1 /demo
}

it outputs..

Code
HTTP/1.1 400 Bad Request
Date: Tue, 24 Dec 2024 15:59:14 GMT
Server: Apache/2.4.62 (Rocky Linux) OpenSSL/3.4.0 mod_fcgid/2.3.9 mod_wsgi/5.0.0 Python/3.11
Content-Length: 226
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>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>


anyone have any ideas what i am doing wrong?

Joined: Jul 2006
Posts: 4,193
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,193
Your GET parameter is not starting with a /, which, as far as I'm concerned, is not possible. This is your 400 error most likely.
But your host header is also incorrect, it should be the same value used in /sockopen.

Your on sockread event also is incorrect on many points.
You need to discard the headers first before looking for your text as your text may appear in headers. And you need better reading logic than just read anything that is available because you may end up with a packet being "TTN" with the next one being "M7", making your if condition fails.
To discard headers you need to use a true/false bool variable to store whether or not you discarded the headers already.
Code
On *:sockread:demo:{
var %r 
Sockread %r
If (!$sockbr) return
If (%headersread) {
If (TTNM7 isin %r) ...
}
Elseif (%r == $null) %headersread = 1
}
}
you will need to make sure %headersread is either unset when the socket close, or reset it when you reopen the socket.

If you are using https 1.1 your connection should stay alive by default and on sockclose won't trigger, you will have to specify a connection: close header.


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

Link Copied to Clipboard