Retrieving results from external HTTP POST

Hey guys. If someone can point me in the right direction; a preliminary search has me scratching my head…

Using LotusScript, if possible, I’d like to be able to POST an HTTP/S form on an external non-Domino server and then retrieve the results. I will then parse the results appropriately.

Examples of why I would need to do this are: payment gateways, integrating with partners to get information from their servers.

What classes/methods are appropriate? Any sample code?

Thanks a million!

Damian

Subject: Retrieving results from external HTTP POST

Continuation…

I have found ways to do this (by searching this board and google) via JAVA and also via LotusScript with MS extensions (which i don’t think my Sun servers will be pleased to run…)

Still searching for a native LotusScript way to do this…

Thx!

D

Subject: RE: Retrieving results from external HTTP POST

If you can do it with Java, then you should be able to do it with LS2J.

Subject: Retrieving results from external HTTP POST

Send the post to an notes agent.

Do something like:

Agent code:

Dim ses As New NotesSession

Dim doc As NotesDocument

Dim urlBase As String

Dim tmp() As Variant

Set doc = ses.DocumentContext

’ Parse out the return url

If ParseRequestContent(doc.Request_Content(0), tmp, “urlBase”) = False Then Error 1292, “Missing urlBase argument” ’ To get the value of urlBase

urlBase = tmp(0)

’ Some functions

Function ParseRequestContent (requestContent As String, resultArray() As Variant, parameter As String) As Integer

' This finction is usable in agents that get an form posted to it with the 'post-method'

' The data comes in the cgi variable request content to the agent (get it with DocumentContext)

' This function make all decoding and stuff, so the requestContent parameter can be supplied 'as is'

' The return value is set to true if averything went well (no error and that it was at least one value found)

' The resultArray is where the result should be 'saved'

' The parameter-parameter is case insensitive



ParseRequestContent = False

On Error Goto errorHandler

Dim rc As String

Dim a As Integer

Dim p As Integer

rc = "&" + DecodePlus(requestContent) ' the ampersand is there to make sure the string starts with an ampersand

a = -1



p = Instr(Lcase$(rc), "&" + Lcase$(parameter) + "=")

While p>0 

	a = a + 1 

	If a = 0 Then

		Redim resultArray(a) As Variant

	Else

		Redim Preserve resultArray(a) As Variant

	End If

	resultArray(a) = Parse(rc, parameter)

	rc = Mid$(rc, p+3)

	p = Instr(Lcase$(rc), "&" + Lcase$(parameter) + "=")

Wend

If a = -1 Then Error 1201, "No parameter found"

ParseRequestContent = True

exitParse:

Exit Function

errorHandler:

ParseRequestContent = False

Resume exitParse	

End Function

Function DecodePlus (encString As String) As String

' Denna rutin ersätter först alla + tecken med blanksteg innan han kallar på Decode



Dim i As Integer



For i = 1 To Len(encString)

	

	If Mid$(encString, i, 1) = "+" Then

		Mid$(encString, i, 1) = " "

	End If

	

Next



DecodePlus = Decode(encString)

End Function

Function Decode(encString As String) As String

' Avkodar en sträng som innehåller %hh i sig där procent hh står för ett hexadecimalt värde på ett tecken

' Blir det fel returnerar rutinen en tom sträng



On Error Goto errorHandling



Dim i As Integer

Dim vString As String



i = Instr(encString, "%")



Do While i > 0

	

	vString = Mid$(encString, i + 1, 2)

	encString = Left$(encString, i -1) + Chr$(Cint("&H" + vString)) + Mid$(encString, i + 3)

	

	i = Instr(i+1, encString, "%")

Loop



Decode = encString



Exit Function

errorHandling:

Decode = ""

End Function

I really dont know if I would do like this today. But we always learn new stuff :slight_smile:

Subject: RE: Retrieving results from external HTTP POST

Henrik,

I really appreciate your effort! However, I think we are talking about 2 different things.

I want an agent that will make the HTTP POST to an external program on someone else’s non-Domino server and retrieve the results from that external program. I do not want post data to a Domino agent as is what you described.

This is a very common process such as integrating with HTTP payment gateways, etc.

BTW, in my ongoing research, I have found a rather complex way of doing this using a SOAP client, Sun Brazil framework (for HTTPRequest class), XML4J parser and Java… ugh. I don’t want to go down this R5 era path until I am sure this is the only way. R6 might have these classes built in!!

p.s. This is so easy to do in PERL… I can do it in one line.

Thanks again!

D