Having problem with WebRequest GetResponse

Rex

Member
Joined
Jan 3, 2008
Messages
9
Programming Experience
10+
I'm trying to issue a CGI command to an Axis camera to obtain information on the camera's position, and I'm issuing the following calls:

VB.NET:
Dim webreq as WebRequest
Dim webresp as WebResponse
Dim strm as StreadReader

webreq = WebRequest.Create("http://192.168.0.10/axis-cgi/com/ptz.cqi?query=position")
webreq.Method = "POST"
webreq.Timeout = 100000
webresp = webreq.GetResponse()  '<<never returns from this call>>
strm = New StreamReader(webresp.GetResponseStream)
When I issue this http command through Internet Explorer, it returns the information on the camera's position. However, when I issue the above sequence of calls, the webreq.GetResponse call never returns/completes.

Any thoughts or suggestions would REALLY be appreciated!!!
 
Last edited by a moderator:
When you're using that address in browser a GET Http request is issued, not a POST. GET is also default method for WebRequest for Http protocol addresses.
 
That's interesting. I started using the default Method, then explicitly set it to webreq.Method = "GET", and found in each case an error was returned "The underlying connection was closed. The server commited an HTTP protocol violation."

I THOUGHT I was making progress with changing the Method to "POST" because I no longer get the HTTP protocol violation.

Any suggestions of what I should look at to identify what I'm doing wrong???
 
When I changed the Method to "GET", I receive an error to the GetResponse that reads "The server committed an HTTP protocol violation". After running a trace, I found the response to the query is being returned as a string of labels and values, but doesn't include a Header.

How can I obtain and use the returned values with the Header missing???
 
Have you tried WebClient? I may be more forgiving (like the IE browser).
VB.NET:
Dim client As New Net.WebClient
Dim url As String = "http://192.168.0.10/axis-cgi/com/ptz.cqi?query=position"
Dim s As String = System.Text.Encoding.ASCII.GetString(client.DownloadData(url))
 
Last chance as I see it, connect with socket and get raw response data, this bypasses the Http protocol WebRequest/WebClient uses:
VB.NET:
Sub httpprot()
    Dim client As New Net.Sockets.TcpClient
    client.Connect("192.168.0.10", 80)
    Dim writer As New IO.StreamWriter(client.GetStream)
    Dim reader As New IO.StreamReader(client.GetStream)
    writer.WriteLine("GET /axis-cgi/com/ptz.cqi?query=position HTTP/1.1")
    writer.WriteLine("Host: 192.168.0.10")
    writer.WriteLine()
    writer.Flush()
    Dim sb As New System.Text.StringBuilder
    While reader.Peek <> -1
        sb.AppendLine(reader.ReadLine)
    End While
    writer.Close()
    reader.Close()
    client.Close()
    MsgBox(sb.ToString)
End Sub
 
Back
Top