GetRequestStream Problem

  • Thread starter Thread starter Chad Szymanski
  • Start date Start date
C

Chad Szymanski

I'm trying to create an HttpWebRequest to a servlet, write some XML to the
request stream, and then read the response which consists of some XML.

The problem is that dotnet thinks the stream is empty even though ethereal
port sniffer tells me I'm getting back the correct response.

Here are the port sniffer capture logs:

The Request:

POST
http://somedomain/ims/servlet/Esrim...sion=3.1&CustomStream=True&ClientLocale=en_CA
HTTP/1.1\r\n
Request Method: POST
Content-Type: text/html\r\n
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n
Content-Length: 470\r\n
Expect: 100-continue\r\n
Proxy-Connection: Keep-Alive\r\n
Host: somedomain\r\n
\r\n

This XML (encoded) is written to the request stream as expected:

<?xml version="1.0" encoding="UTF-8"?><ARCXML
version="1.1"><REQUEST><GET_IMAGE><PROPERTIES><ENVELOPE
minx="288739.501779" miny="4823077.313167125" maxx="338000.0"
maxy="4860022.686832875" /><IMAGESIZE width="596" height="447"
dpi="96" /><LAYERLIST order="true"><LAYERDEF id="1000"
visible="false" /><LAYERDEF id="2000" visible="false" /><LAYERDEF
id="2025" visible="false" /><LAYERDEF id="1600" visible="false"
/></LAYERLIST></PROPERTIES></GET_IMAGE></REQUEST></ARCXML>

The Response I get is:

Hypertext Transfer Protocol
HTTP/1.0 200 OK\r\n
Response Code: 200
Date: Thu, 02 Sep 2004 13:23:35 GMT\r\n
Server: IBM_HTTP_SERVER/1.3.19.5 Apache/1.3.20 (Unix)\r\n
Set-Cookie: JSESSIONID=00005W1U2WFLVKWUZFVXIU45Q2Q:v8t1l49a;Path=/\r\n
Cache-Control: no-cache="set-cookie,set-cookie2"\r\n
Expires: Thu, 01 Dec 1994 16:00:00 GMT\r\n
Content-Type: text/html\r\n
Content-Language: en\r\n
X-Cache: MISS from somedomain\r\n
X-Cache-Lookup: MISS from somedomain:3128\r\n
Proxy-Connection: close\r\n
\r\n
Line-based text data: text/html
\000\000\000d\000\000\000\266<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<RESPONSE>
<IMAGE>
<ENVELOPE minx="288739.501779" miny="4823077.31316712" maxx="338000"
maxy="4860022.68683287" />
\000\000\000d\000\000\000\324<OUTPUT
url="http://somedomain/lit/common/ImageF...erdomain:8002/output/OrthoImagery21565710.jpg"
/>
</IMAGE>
</RESPONSE>
</ARCXML>
\000\000\000f

Here is my corresponding vb.net code:

szURL = "http://" + szServerName +
"/ims/servlet/Esrimap?ServiceName=" + szServiceName +
"&ClientVersion=3.1&CustomStream=True&ClientLocale=en_CA"

Dim szPost As String = "<?xml version=""1.0""
encoding=""UTF-8""?><ARCXML
version=""1.1""><REQUEST><GET_IMAGE><PROPERTIES><ENVELOPE
minx=""288739.501779"" miny=""4823077.313167125"" maxx=""338000.0""
maxy=""4860022.686832875"" /><IMAGESIZE width=""596"" height=""447""
dpi=""96"" /><LAYERLIST order=""true""><LAYERDEF id=""1000""
visible=""false"" /><LAYERDEF id=""2000"" visible=""false"" /><LAYERDEF
id=""2025"" visible=""false"" /><LAYERDEF id=""1600"" visible=""false""
/></LAYERLIST></PROPERTIES></GET_IMAGE></REQUEST></ARCXML>"
Dim encoding As New ASCIIEncoding
Dim bytes() As Byte = encoding.GetBytes(szPost)

Dim httpWebReq As HttpWebRequest = CType(WebRequest.Create(szURL),
HttpWebRequest)

httpWebReq.Method = "POST"

httpWebReq.Proxy = wp
httpWebReq.ContentLength = szPost.Length
httpWebReq.ContentType = "text/html"
httpWebReq.KeepAlive = True
httpWebReq.Accept = "text/html"

Try

Dim reqStream As Stream = httpWebReq.GetRequestStream
reqStream.Write(bytes, 0, bytes.Length)
reqStream.Close()

Dim result As String
Dim pReader As StreamReader = New
StreamReader(httpWebReq.GetResponse.GetResponseStream)

result = pReader.ReadToEnd
MsgBox(result)
pReader.Close()

Catch ex As Exception

End Try


The result is that the result string is empty. My guess is that
the "\0" represents an end of stream character which leads to the
readtoend function to terminate prematurely. Similarly if I try to get
the length of the response steram it is always -1. Any ideas as to what
the problem is and how to resolve it?


--Chad Szymanski
 
Back
Top