This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Using ? in HTTP grab sockets

Help for those learning Tcl or writing their own scripts.
Post Reply
N
Nara
Halfop
Posts: 40
Joined: Sun Jul 23, 2006 11:12 pm

Using ? in HTTP grab sockets

Post by Nara »

Alright, I'm trying to access a server using this code:

Code: Select all

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 \.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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?
N
Nara
Halfop
Posts: 40
Joined: Sun Jul 23, 2006 11:12 pm

Post by Nara »

I honestly have no knowledge of how the http package works or where to obtain it, hence my use of sockets.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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.
Post Reply