Link to home
Create AccountLog in
Avatar of keith1001
keith1001Flag for United States of America

asked on

Visual Basic - Getting web data help needed

I am trying to get the XML data returned for a stock "F" (ford) from webservicex.net but my text box never shows anthing:
Imports System
Imports System.IO
Imports System.Net
Imports System.Text

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim reader As StreamReader

        Try

            request = WebRequest.Create("http://www.webservicex.net/stockquote.asmx?F")
            request.Method = "POST"
            ' Get response   
            request.ContentType = "text/xml"
            request.Headers.Add("SOAPAction", "http://webserviceX.NET/GetQuote")
            response = DirectCast(request.GetResponse(), HttpWebResponse)
            reader = New StreamReader(response.GetResponseStream())
            txtOutput1.Text = (reader.ReadToEnd())

        Finally
            If Not response Is Nothing Then response.Close()
        End Try

    End Sub
End Class

Open in new window

Avatar of bansidhar
bansidhar
Flag of India image

there are some things you are missing. Strange that you are able to run the code, as there is exception in your code.

you need to set the query xml and the content length check their page

http://www.webservicex.net/stockquote.asmx?op=GetQuote
Avatar of Nasir Razzaq
Try this code



request = WebRequest.Create("http://www.webservicex.net/stockquote.asmx/GetQuote?Symbol=" & TheValueForSymbolParameter)
            response = request.GetResponse()
            reader = New StreamReader(response.GetResponseStream())
            txtOutput1.Text = (reader.ReadToEnd())

Open in new window

Avatar of keith1001

ASKER

CodeCruiser - I could not get that to work either, was you able to?

banisdhar - But how do I know content length?  Do you know what the exception is?

emoreau - Thanks for that link!
ASKER CERTIFIED SOLUTION
Avatar of bansidhar
bansidhar
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account