Full Version: HTTP POST
UtterAccess Discussion Forums > And More... > Web Development
highwayrob
VB.NET in Visual Studio 2005 has the HTTPWebRequest HTTPWebResponse functions for Post\Get built in to the language. Do these same functions exist in Access 2007?

I am trying to POST a query to a webserver that will return XML data and this is the specified method to 'POST" the data request.

Thanks,

Rob
datAdrenaline
I would suggest that you reference the "Microsoft XML, x.x" library. In that library you have .open and .send methods associated with an MSXML2.XMLHTTPxx object. They are analogous to what you do with the HTTPWebRequest object. The response comes back through the MSXML2.XMLHTTPxx object with the methods .responseText or .responseXML

Here are some threads that may help ...

http://support.microsoft.com/kb/290591
http://msdn.microsoft.com/en-us/library/ms756095(VS.85).aspx <-- This one will get you to some MSDN stuff that will probably be useful ...

....

Disclaimer .... I have NOT been succussful with posting yet in Access (C# ... yes) ... I am quite new to all this technology, and have been learning through this week ... and JUST TODAY, to found the info I just relayed to you. I do send something to the XML service I am posting to, but I just get an errant response, so I think I will have to learn more about the settings, ie: like the content type ... which in VBA is set with ...

.setRequestHeader "Content-Type", " .... "

.....

I hope this helps! .... AND PLEASE let me see your code if you achieve successful communication! ...
highwayrob
LOL...quite a coincidence....I will check out what you sent and if I am successfull, I will report back.

Thank you,

Rob
datAdrenaline
WOOO HOOO! ... I have succussful communication in A2007 ....

CODE
Public Sub GetMeetings()
    
    Dim reqHTTP As New MSXML2.XMLHTTP50  'Reference set to Microsoft XML, 5.0 (This came with A2007)
  
    Dim strXMLRequest As String
    Dim strXMLResponse As String
    
    strXMLRequest = strXMLRequest & "<?xml version=""1.0"" encoding=""ISO-8859-1""?>"
    strXMLRequest = strXMLRequest & "<serv:message xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" " & _
                                    " xmlns:serv=""http://www.webex.com/schemas/2002/06/service"">"
    
    ''''''''''''''''''''''''''''''''''''''''''''''''
    '<the rest of my XML request is in this chunk>
    ''''''''''''''''''''''''''''''''''''''''''''''''
    strXMLRequest = strXMLRequest & "</serv:message>"
        
    'Prepare the request (I am hitting webex ...)
    reqHTTP.Open "POST", "https://hslda.webex.com/WBXService/XMLService", False
    reqHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    
    'Send (post) the request to the service
    reqHTTP.send strXMLRequest
    
    'Wait for the response to be ready (mine works with out this, but I found some samples with it)
    While reqHTTP.readyState <> 4
        DoEvents
    Wend
    
    'Show the response
    Debug.Print reqHTTP.responseText  'Outputs response as one long string
    
    ''''''''''''''''''''''''''
    '... Or this works too ...
    'Debug.Print reqHTTP.responseXML.XML
    ''''''''''''''''''''''''''
End Sub
schroep
I've actually had good success with this in the past, here's a basic shell that uses the XML 3.0 reference:
CODE
' Created 5-15-2002 by Peter M. Schroeder
' Modified 4-23-2009 by Peter M. Schroeder (turned into a generic template for posting to UtterAccess)
Public Function gfncXMLPost() As Variant
    Dim objXMLDOC As New DOMDocument30
    Dim objXMLHTTP As New XMLHTTP30
    
    objXMLHTTP.Open "POST", "http://addressgoeshere", False
    objXMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    objXMLHTTP.send "yourXMLstringgoeshere"
    objXMLDOC.validateOnParse = True ' Convert response to XML
    objXMLDOC.loadXML objXMLHTTP.responseText
    If objXMLDOC.parseError.errorCode = 0 Then ' If no errors:
'     parse the response here
    End If
    Set objXMLDOC = Nothing
    Set objXMLHTTP = Nothing
End Function
datAdrenaline
Awesome peter! .... Now, I just need to figure out how to use an XMLDoc object (or just parse the simple XML text) to write the node values to a SQL server table ... I don't suppose you do something similar?
schroep
This isn't exactly what you are looking for, but perhaps you can build on it (this is taken from a routine that looks up UPS Time in Transit information):
CODE
    If objXMLDOC.parseError.errorCode = 0 Then ' If no errors:
        Set objNodes = objXMLDOC.documentElement.selectNodes("TransitResponse/ServiceSummary") ' Look for ServiceSummary nodes in response
        If objNodes.length > 0 Then ' If any exist:
            Set objNode = objXMLDOC.documentElement.selectSingleNode("TransitResponse/TransitFrom/AddressArtifactFormat") ' Check returned FROM values
            strFromCity = objNode.selectSingleNode("PoliticalDivision2").Text
            strFromState = objNode.selectSingleNode("PoliticalDivision1").Text
            strFromZip = objNode.selectSingleNode("PostcodePrimaryLow").Text
            Set objNode = objXMLDOC.documentElement.selectSingleNode("TransitResponse/TransitTo/AddressArtifactFormat") ' Check returned TO values
            strToCity = objNode.selectSingleNode("PoliticalDivision2").Text
            strToState = objNode.selectSingleNode("PoliticalDivision1").Text
            strToZIP = objNode.selectSingleNode("PostcodePrimaryLow").Text
            If (strFromCity = pstrFromCity) And (strFromState = pstrFromState) And (strFromZip = pstrFromZip) And (strToCity = pstrToCity) And (strToState = pstrToState) And (strToZIP = pstrToZip) Then ' If returned values match passed-in values (no correction took place with UPS)
                For Each objNode In objNodes ' Cycle through them
                    If objNode.selectSingleNode("Service/Code").Text = "GND" Then ' Look for a Ground entry
                        gfncUPS_TimeInTransit = CLng(objNode.selectSingleNode("EstimatedArrival/BusinessTransitDays").Text) ' Return the Ground days in transit
                        Exit For
                    End If
                Next
            End If
            Set objNode = Nothing
        End If
        Set objNodes = Nothing
    End If
datAdrenaline
Hello Peter ...

Thank you very much, that definately helps out! ... To make a long story short, I am learning C# since I am now
a C# programmer, wooo hooo! (by title at least) ... so as I am given tasks, I will often try to duplicate the
process is good ole VBA ... It helps me gather my thoughts, and typically helps extend the VBA stuff I still
create & support.

Anyway ... I truly appreciate the help, your sample is quite informative and will help a ton thumbup.gif
schroep
C#, eh? Well, congrats! I've dabbled with it a bit, but haven't jumped in head first (yet, anyway).

Are you using it with JET backends, or moving away from that, as well? It would be nice to see direct Access support for some of the .NET languages in the future.
BananaRepublic
Peter,

You probably already know that but wanted to mention that at least for time being, .NET can be made to integrate with Access via COM. In fact, I adapted two C# libraries for my last project's needs and could manage it through VBA.

I, for one, am likewise rooting for eventual .NET integration in Access. sad.gif

XML, on the other hand, remains something that I'll have to learn about. dazed.gif
schroep
Yep, I am rooting for direct support.

It would be nice to code in a choice of languages in MS Office, rather than solely VBA.
mishej
There are ways to use .NET code integration now. I just delivered my first app that integrates a .NET COM DLL that will allow me to later replace with newer version by simplying copying over the existing DLL!

This isn't native integration but you can leverage the abilities of .NET from within Access.

I use late binding ( CreateObject(sAppClassName) ) so no reference is needed. I do check that the .DLL exists where I expect it first.

In .NET I create a Class Library (using VB.Net) and checked the "Make Assembly COM-Visible" checkbox on the pop-up displayed when you click on the "Assembly Information..." button on the Application tab of the Project settings.

If this interests any readers here are some of the resources I have saved on this issue:

VBA interoperability with .NET with Excel, Word, etc.
------------------------------------------

HOW TO: Call a Visual Basic .NET Class Library from Visual Basic for Applications in Microsoft Office
http://support.microsoft.com/kb/317535

Visual Studio Tools for the Office System (3.0)
http://msdn2.microsoft.com/en-us/library/bb871648.aspx

Interoperability Between VBA and Visual Studio Tools for the Office System (3.0)
http://msdn2.microsoft.com/en-us/library/bb814696.aspx

MSDN Blog:
http://blogs.msdn.com/vsto2/

Installing and Using the Office 2003 Primary Interop Assemblies
http://msdn2.microsoft.com/en-us/library/a...office.11).aspx


Calling Managed Code from Access VBA
-------------------------------------

Is there a way that my Access VBA Applications can reference a VB.NET DLL?
I have tried using the COM Interop Feature but have had no success. Any
help would be appreciated...

Brendan Reynolds responded on May 31 2005, 2:15 pm
Newsgroups: microsoft.public.access

COM Interop goes the other way - it permits the use of COM components in
managed code.

If you're using Access 2002 or Access 2003, you can use the Web Services
Toolkit to call a Web Service. If your DLL isn't already a Web Service,
you'll need to write one to wrap the DLL.

Microsoft Office XP Web Services Toolkit
http://msdn.microsoft.com/library/default....kitoverview.asp

Microsoft Office XP Web Services Toolkit 2.0
http://www.microsoft.com/downloads/details...;displaylang=en

A Beginner’s Guide to calling a .NET Library from Access
http://richnewman.wordpress.com/2007/08/25...ry-from-access/
--- uses .NET library as a reference -- done by setting COM related attributes of the .NET project

Exposing COM interfaces of a .NET class library for Late Binding
http://www.codeproject.com/KB/vb/MusaExposingCOM.aspx
--- uses .NET library via late-binding (CreateObject) - uses COM Class template in .NET

Managed Add-Ins for Access 2007
http://msdn2.microsoft.com/en-us/library/aa902693.aspx

COM Interoperability in .NET Part 2 - Generating a Type Library (RegAsm.exe)
http://www.developerfusion.co.uk/show/2134/3/

The regasm.exe utility not only registers an assembly and it also creates the
required type library file, as shown here:

regasm Server.dll /tlb:Netserver.tlb /codebase

and you can un-install with:

regasm /u Server.dll /tlb:Netserver.tlb /codebase


VB6 interoperability with .NET
-------------------------------

Interop Forms Toolkit 2.0
http://msdn2.microsoft.com/en-us/vbasic/aa701259.aspx


.NET to COM interoperability
-----------------------------

Microsoft .NET/COM Migration and Interoperability - Patterns and Practices
http://msdn2.microsoft.com/en-us/library/ms978506.aspx
datAdrenaline
Hey Peter ...

>> Are you using it with JET backends <<
Nope ... not in C#, some of the apps we support were written in Access and those are JET. Most of my Access
apps used SQL server backends, however, I supported some JET BE systems through contract work and personal
solutions ... so it will be more more like ... "I will be working with JET just as much as I was". smirk.gif

>> It would be nice to see direct Access support for some of the .NET languages in the future <<
... it seems others have posted some great links! ... I would love to see the future go to VSA (Visual Studio for
Applications) and subsequently let the developer use C#, VB.Net or a blend in their applications.... completely
taking VBA out would be a huge hurdle to cross!
BananaRepublic
I agree. My sticking point was simply smoothing out the transition. Right now, it's a big step between an Access application and a full-on standalone application but if there was a mean of better integration with VSA and .NET, then it would be easier for IT and developer to adopt the homegrown application created by knowledge workers that became mission critical without having to re-invest so much money and time in migrating both the data (relatively easy) and the code needed to support the interface (not so easy) from a desktop solution full of macros to an enterprise solution with n-tiered architecture.

Luke Chung already wrote about how database evolves and to me that was a pretty significant insight in how Access ought to be packaging. Of course, I'll gladly concede the point that Luke also said that only 2% actually go up a next step. Even so, I don't think it should rule out the possibility of providing a smooth transition from one end to other.

But that's up to Microsoft to decide if it's worth it. I suppose.
mateo333
Peter,

I used your code in a project of mine, and although it does work...I receive a lot of failure messages back from the asp that I am posting to. Is there any sort of pause that could be applied between posts? I have a loop setup that formulates my xml message and then sends the post. Typically this loop could generate around 3000 xml messages to the asp. My most recent test only successfully communicated 90 messages, the rest failed.

Thanks!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.