[Mapserver-users] Passing CGI variables
Dharani Babu
dharanibabus at hotmail.com
Fri Apr 16 08:50:28 PDT 2004
Hi all
Thanks to all for the replies . I got it all working . Yes in fact the
QUERY_STRING value can be just posted to the map_serv.exe programmatically .
I just now found the rigth way to parse the output from MS exe . No xml http
requests needed . And more over for new users this info can be useful .
1) To use the MS exe WITHOUT apache or IIS just I did the following ( I
request all of the members to advise me on this method of just "moving" the
contents of cgi-bin )
Copy all the contents of C:/ms4w/apache/cgi-bin or
C:/Inetpub/wwwroot/Scripts - C:/Inetpub/wwwroot/bin to some other folder for
ex C:/Test .
Now from the command prompt set the environment variable
C:/> set REQUEST_METHOD= "GET"
Now the CGI vairables can be passed easily as like firing an exe - no need
for IIS / Apache or http request like http://localhost/mapserv.exe ?
QUERY_STRING = map " ...etc . After passing the variables the output from
standard output can be parsed easily and faster also .My vb.net code is as
follows .
Imports System.IO.StreamReader
Public Class Form1
Inherits System.Windows.Forms.Form
Dim strXY As String
Dim url As String
Dim strEXT As String
Dim mainTxt As String
Dim countyTxt As String
Dim flag As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ProgressBar1.Value = 0
ProgressBar1.Visible = True
ProgressBar1.PerformStep()
Dim myProcess As New Process
Dim myProcessStartInfo As New
ProcessStartInfo("C:/Test/mapserv_40.exe", mainTxt)
myProcessStartInfo.CreateNoWindow = True
myProcessStartInfo.UseShellExecute = False
myProcessStartInfo.RedirectStandardOutput = True
myProcess.StartInfo = myProcessStartInfo
myProcess.Start()
ProgressBar1.PerformStep()
ProgressBar1.PerformStep()
Dim myStreamReader As System.IO.StreamReader =
myProcess.StandardOutput
' Read the standard output of the spawned process.
Dim myString As String = myStreamReader.ReadToEnd
'MsgBox(myString)
'Console.WriteLine(myString)
myProcess.Close()
url = myString
Dim objdocument
objdocument = CreateObject("HTMLFILE")
objdocument.open("text/html")
objdocument.write(url)
Dim objforms
Dim ctrl
Dim strpath
Dim arr(3) As String
Dim imgxy() As String
Dim imgext() As String
Label2.Text = "Parsing standard output "
For Each objforms In objdocument.documentElement.document.Forms
For Each ctrl In objforms.getElementsByTagName("*")
If ctrl.tagName = "INPUT" Then
If ctrl.Name = "img" Then
arr = Split(ctrl.src, "/")
End If
If ctrl.Name = "imgxy" Then
strXY = ctrl.Value
End If
If ctrl.Name = "imgext" Then
strEXT = ctrl.Value
End If
End If
Next
Next
ProgressBar1.PerformStep()
ProgressBar1.PerformStep()
objdocument.close()
strpath = "C:\ms4w\Apache\htdocs\temp_rm6\" & arr(2)
PictureBox1.BorderStyle = BorderStyle.Fixed3D
PictureBox1.Image = Image.FromFile(strpath)
ProgressBar1.PerformStep()
ProgressBar1.PerformStep()
ProgressBar1.PerformStep()
ProgressBar1.PerformStep()
ProgressBar1.PerformStep()
ProgressBar1.PerformStep()
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
Dim xpos
Dim ypos
Dim strtemp
xpos = e.X()
ypos = e.Y()
strtemp = "QUERY_STRING=zoomdir=1&zoomsize=2&"
strtemp = strtemp & "imgxy=" & Replace(strXY, " ", "+") & "&imgext="
& Replace(strEXT, " ", "+") & ""
strtemp = strtemp & "&map=C%3A%2Fms4w%2Fapache%2Fhtdocs%2Fdemof%2F"
& countyTxt &
"&savequery=true&program=%2Fcgi-bin%2Fmapserv_40.exe&map_web_imagepath=c%3A%2Fms4w%2FApache%2Fhtdocs%2Ftemp_rm6%2F&map_web_imageurl=%2Ftemp_rm6%2F"
strtemp = strtemp & "&img.x=" & xpos & "&img.y=" & ypos
Dim myProcess As New Process
Dim myProcessStartInfo As New
ProcessStartInfo("C:/Test/mapserv_40.exe", strtemp)
myProcessStartInfo.CreateNoWindow = True
myProcessStartInfo.UseShellExecute = False
myProcessStartInfo.RedirectStandardOutput = True
myProcess.StartInfo = myProcessStartInfo
myProcess.Start()
Dim myStreamReader As System.IO.StreamReader =
myProcess.StandardOutput
' Read the standard output of the spawned process.
Dim myString As String = myStreamReader.ReadToEnd
url = myString
Dim objdocument
objdocument = CreateObject("HTMLFILE")
objdocument.open("text/html")
objdocument.write(url)
Dim objforms
Dim ctrl
Dim strpath
Dim arr() As String
For Each objforms In objdocument.documentElement.document.Forms
For Each ctrl In objforms.getElementsByTagName("*")
If ctrl.tagName = "INPUT" Then
If ctrl.Name = "img" Then
arr = Split(ctrl.src, "/")
End If
If ctrl.Name = "imgxy" Then
strXY = ctrl.Value
End If
If ctrl.Name = "imgext" Then
strEXT = ctrl.Value
End If
End If
Next
Next
objdocument.close()
strpath = "C:\ms4w\Apache\htdocs\temp_rm6\" & arr(2)
PictureBox1.BorderStyle = BorderStyle.Fixed3D
PictureBox1.Image = Image.FromFile(strpath)
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
mainTxt =
"QUERY_STRING=map=C%3A%2Fms4w%2Fapache%2Fhtdocs%2Fdemof%2Frockshp1_pic.map&layer=tigerdata&zoomdir=1&zoomsize=2&program=%2Fcgi-bin%2Fmapserv_40.exe&map_web_imagepath=C%3A%2Fms4w%2Fapache%2Fhtdocs%2Ftemp_rm6%2F&map_web_imageurl=%2Ftemp_rm6%2F"
countyTxt = "rockshp1_pic.map"
flag = 0
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
mainTxt =
"QUERY_STRING=map=C%3A%2Fms4w%2Fapache%2Fhtdocs%2Fdemof%2Fsuff_pic.map&layer=tigerdata&zoomdir=1&zoomsize=2&program=%2Fcgi-bin%2Fmapserv_40.exe&map_web_imagepath=C%3A%2Fms4w%2Fapache%2Fhtdocs%2Ftemp_rm6%2F&map_web_imageurl=%2Ftemp_rm6%2F"
countyTxt = "suff_pic.map"
flag = 1
End Sub
'Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
' mainTxt = ""
' countyTxt = ""
'End Sub
End Class
with regards and thanks
Dharani Babu S
>From: "Daniel Morissette" <dmorissette at dmsolutions.ca>
>To: <RCorbet>
>CC: "Dharani Babu"
><dharanibabus at hotmail.com>,<mapserver-users at lists.gis.umn.edu>
>Subject: Re: [Mapserver-users] Passing CGI variables
>Date: Fri, 16 Apr 2004 15:00:21 +0100
>
>David Mitchell wrote:
>>Dharani,
>>
>>REQUEST_METHOD and QUERY_STRING are environment variables, not parameters
>>to the application. Try this instead:
>>
>>C:\TEST>set "REQUEST_METHOD=GET"
>>C:\TEST>set "QUERY_STRING=map=c:\....."
>>C:\TEST>mapserv_40.exe
>>
>
>For the record, QUERY_STRING=... is a special parameter to the mapserv.exe
>that has the same effect as setting the above environment variables. i.e.
>the following will work:
>
>
>C:\TEST>mapserv_40.exe "QUERY_STRING=map=C%3A%2Fms4w%2Fapa..."
>
>Daniel
>--
>------------------------------------------------------------
> Daniel Morissette dmorissette at dmsolutions.ca
> DM Solutions Group http://www.dmsolutions.ca/
>------------------------------------------------------------
>
>_______________________________________________
>Mapserver-users mailing list
>Mapserver-users at lists.gis.umn.edu
>http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>
_________________________________________________________________
Strike the right balance! News, gossip n fundas!
http://www.msn.co.in/women/ Get it all at MSN Women!
More information about the MapServer-users
mailing list