| View previous topic :: View next topic |
| Author |
Message |
Nara Halfop
Joined: 23 Jul 2006 Posts: 40
|
Posted: Fri Apr 06, 2007 8:21 pm Post subject: Using ? in HTTP grab sockets |
|
|
Alright, I'm trying to access a server using this code:
| Code: | proc battle:flistenersdata { } {
global shoutcast shoutport shoutpass url_ xml_ fd_ state_
set url_ "/radiosite/modules.php?name=Nuke-Cast"
set xml_ ""
# Setting up timeout length
after 3000 set state_ timeout
set fd_ [socket -async CENSORED CENSORED]
fconfigure $fd_ -buffering line -buffersize 1024
fileevent $fd_ writable {
puts $fd_ "GET $url_ HTTP/1.0\nUser-Agent: CENSORED (Mozilla Compatible)\n"
while { ![eof $fd_] } {
gets $fd_ line
append xml_ $line
}
set state_ connected
}
vwait state_
close $fd_
after cancel set state_ timeout
return $xml_
} |
However, I can only access this: /radiosite/modules.php. The ? in the url breaks the http grab. Do you have any ideas on fixing this? I have already tried a \. |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Sat Apr 07, 2007 7:26 pm Post subject: |
|
|
I use ? in the weather script and it works.. Maybe the site you're trying to access is using POST method, not GET?
Here's an example of using POST from one of mc8's scripts (mcbanchan)
puts $sid "POST /report_bug.tcl HTTP/1.0\
\nHost: mc.purehype.net:80\
\nContent-type: application/x-www-form-urlencoded\
\nContent-Length: [expr [string length $query] +2]"
puts $sid \n$query
Here's an example from the weather script (using GET):
set webpage "/cgi-bin/findweather/getForecast?query=$location"
puts $wzsock "GET $webpage"
Why use the socket code anyway, when the http package gives you much more facility? |
|
| Back to top |
|
 |
Nara Halfop
Joined: 23 Jul 2006 Posts: 40
|
Posted: Sun Apr 08, 2007 10:58 am Post subject: |
|
|
| I honestly have no knowledge of how the http package works or where to obtain it, hence my use of sockets. |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Sun Apr 08, 2007 6:27 pm Post subject: |
|
|
| The http package is part of the newer versions of tcl, so you should already have it, and its manpage http.html. There's tons of example scripts in the archives and in the forums about how to use the http package, I've written a lot of scripts using it so look around. |
|
| Back to top |
|
 |
|