• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2434
  • Last Modified:

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
0
dbsoracle
Asked:
dbsoracle
  • 3
1 Solution
 
vbturboCommented:
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
0
 
dbsoracleAuthor Commented:
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.
0
 
vbturboCommented:
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
0
 
vbturboCommented:
sorry

HttpWebRequest Class
WebRequest.PreAuthenticate Property

http://msdn2.microsoft.com/en-us/library/system.net.webrequest.preauthenticate.aspx
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now