Link to home
Start Free TrialLog in
Avatar of dbsoracle
dbsoracle

asked on

VB.net http request and response

Hello:
I am trying to convert the following Access 2003 code into vb.net 2.0
Thanks in advance for any help.

Any Ideas?
 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CallAPI(strXML As Variant)
Dim objXMLHTTP, dblqte As String
' Build the XML Open statement & Header Info
Set Misc = CurrentDb.OpenRecordset("Misc")
Misc.MoveFirst
url = Trim(Misc![url])
uname = Trim(Misc![username])
pwd = Trim(Misc![password])
Misc.Close
url = url & strXML
' Call the XMLHTTP Library functions
Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.Open "POST", url, False, uname, pwd
objXMLHTTP.SetRequestHeader "Content-type", "application/x-www-form-urlencoded"
objXMLHTTP.Send
'Debug.Print objXMLHTTP.ResponseText
CallAPI = objXMLHTTP.ResponseText
End Function
Avatar of vbturbo
vbturbo
Flag of Denmark image

Hi

It would be something like this , though you can change the local path to an URL instead  
and read the data into a datatable

  Private Sub Getdata()

     Dim ds As New DataSet()

        Dim reader As XmlTextReader = New System.Xml.XmlTextReader("C:\test.xml")

        Dim dtbl As New DataTable
        Dim dr As DataRow
        Dim dv As New DataView(dtbl)

        Dim objNodes As New System.Xml.XmlDocument
        objNodes.Load(reader)
        Dim oNodes As System.Xml.XmlNodeList
        'set the parent node from where you want to start to read the child nodes.
        oNodes = objNodes.SelectNodes("//spot")

        dtbl.Columns.Add(New DataColumn("col1", GetType(String)))
        dtbl.Columns.Add(New DataColumn("col2", GetType(String)))

        Dim node As System.Xml.XmlNode

        For Each node In oNodes

            dr = dtbl.NewRow()
            dr(0) = node.Attributes.GetNamedItem("id").Value
            dr(1) = node.Attributes.GetNamedItem("num").Value
            'dr(1) = node.Item("file").InnerText 'regular node reading
            dtbl.Rows.Add(dr)

        Next
        ds.Tables.Add(dtbl)
 
    End Sub

hope this helps

vbturbo
Avatar of dbsoracle
dbsoracle

ASKER

Hi VBTurbo:
Thanks much for responding.  The Access code actually calls a web service over the internet and that web service returns xml. In digging through .net, I think I need the HttpWebRequest and HttpWebResponse object. In order to call the web service, I also need to pass in user/password and I dont know how to attach that to the HttpWebRequest object, or possibly use .net's web services...???

Thanks much.
Hi
well here is a link regarding HttpWebRequest and sending credentials to the server ,though regarding webservice's my knowledge is zero

HttpWebRequest Class
WebRequest.PreAuthenticate Property

And the IAuthenticationModule.Authenticate Method
http://msdn2.microsoft.com/en-us/library/system.net.iauthenticationmodule.authenticate(VS.71).aspx

vbturbo
ASKER CERTIFIED SOLUTION
Avatar of vbturbo
vbturbo
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial