[AccessD] A2003: POST a set of params to a Web Resource

Stuart McLachlan stuart at lexacorp.com.pg
Thu Jul 11 21:56:09 CDT 2019


Sorry about the delay.  But I couldn't find a good example.

I've just had to write one this morning to post an authetication code and retrieve a zip file, so 
the following version  is based loosely on that.

You need to URL encode your data. URL ENCODE/DECODE functions follow the main code.

---- Code HTTP POST-------------

Option Compare Database
Option Explicit

Function GetDBDump()
'Requires a reference to Microsoft XML 2.0 or greater
'I've use Microsoft XML 6.0 in Office 10.

Dim myXMLHTTP As XMLHTTP60
Set myXMLHTTP = New XMLHTTP60
Dim strResult As String
Dim strPostData as String
strPostData = URLEncode("text=This is  theTask Name for Task No: 4&description=This is 
the Description for Task No: 4&dueDate:'2019-10-07'")
myXMLHTTP.Open "POST", _
    "http://www.example.com/addtask.php", False
myXMLHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows 
NT 5.0)"
myXMLHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
myXMLHTTP.send strPostData 
strResult = myXMLHTTP.responsetext
debug.print strResult
Set myXMLHTTP = Nothing
End Function


--------------END HTTP POST -------------------------------------

-------------URL ENCODE/DECODE ---------------------------------

Public Function URLEncode(StringToEncode As String, Optional _
   UsePlusRatherThanHexForSpace As Boolean = False) As String

Dim TempAns As String
Dim CurChr As Integer
CurChr = 1
Do Until CurChr - 1 = Len(StringToEncode)
  Select Case Asc(Mid(StringToEncode, CurChr, 1))
    Case 48 To 57, 65 To 90, 97 To 122
      TempAns = TempAns & Mid(StringToEncode, CurChr, 1)
    Case 32
      If UsePlusRatherThanHexForSpace = True Then
        TempAns = TempAns & "+"
      Else
        TempAns = TempAns & "%" & Hex(32)
      End If
   Case Else
         TempAns = TempAns & "%" & _
              Format(Hex(Asc(Mid(StringToEncode, _
              CurChr, 1))), "00")
End Select

  CurChr = CurChr + 1
Loop

URLEncode = TempAns
End Function


Public Function URLDecode(StringToDecode As String) As String

Dim TempAns As String
Dim CurChr As Integer

CurChr = 1

Do Until CurChr - 1 = Len(StringToDecode)
  Select Case Mid(StringToDecode, CurChr, 1)
    Case "+"
      TempAns = TempAns & " "
    Case "%"
      TempAns = TempAns & Chr(Val("&h" & _
         Mid(StringToDecode, CurChr + 1, 2)))
       CurChr = CurChr + 2
    Case Else
      TempAns = TempAns & Mid(StringToDecode, CurChr, 1)
  End Select

CurChr = CurChr + 1
Loop

URLDecode = TempAns
End Function



On 11 Jul 2019 at 9:54, Darren - Active Billing wrote:

> Hi Stuart
> 
> Many thanks. I see this post did make it and I even got a response.
> Apologies for missing this - yes, I'd be most grateful, thanks
> 
> Darren. 
> 
> 
> On 11/7/19, 7:53 am, "AccessD on behalf of Stuart McLachlan"
> <accessd-bounces at databaseadvisors.com on behalf of
> stuart at lexacorp.com.pg> wrote:
> 
>     SHELL with that string and let cURL do it?
> 
>     I'll dig out some actual POST code a bit later.
> 
>     On 10 Jul 2019 at 23:04, Darren - Active Billing wrote:
> 
>     > Howdy all,
>     > 
>     > 
>     > 
>     > How would I get the following string to be POSTed to a web site
>     using > VBA? > > > > This is the final and formatted string that
>     works when sending the > CURL request via a Terminal session > > >
>     > curl -XPOST -H "Content-type: application/json" -d '{"text":
>     "This is > the Task Name for Task No: 4","description": "This is
>     the Description > for Task No: 4","dueDate": "2019-10-07"}' >
>     'https://hooks.workast.app/1234567890 > > > > I tried to modify
>     some code I got from Stuart (ages ago) but no > success. I have no
>     clue ...that´s why > > > > FYI: Workast is a site that allows for
>     the addition of tasks for staff > to review - Simple enough but
>     can´t get the POSTing bit from > Access to work > > > > Many
>     thanks in advance > > > > Darren > > -- > AccessD mailing list >
>     AccessD at databaseadvisors.com >
>     http://databaseadvisors.com/mailman/listinfo/accessd > Website:
>     http://www.databaseadvisors.com
> 
> 
> 
>     -- 
>     AccessD mailing list
>     AccessD at databaseadvisors.com
>     http://databaseadvisors.com/mailman/listinfo/accessd
>     Website: http://www.databaseadvisors.com
> 
> 
> 
> 
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com





More information about the AccessD mailing list