HTTP Post and GET

Does anyone have any good examples of performing an HTTP POST and GET with LotusScript? I have an application that will be interfacing with a web service and require this functionality.

Any help or examples would be appreciated.

Steve

Subject: HTTP Post and GET

I do not have any examples using a web service but here is how to handle a post with a url to an agent.

If you plan to have an agent read the data being posted you usually put the url to the agent in the HTML tag’s action property such as.

You can also trigger it with a javascript function like this

function switchAndSubmit() {

document.forms[0].action = ‘’;

document.forms[0].submit();

}

The submit causes the fields and their values to be sent as a string in the format fieldname=value&fieldname2=value etc.

This string is stored in the REQUEST_CONTENT field in the context document of the agent. You just parse the string from this field.

It can get a little more complicated if you have a lot of values. Earlier versions of Notes had a limit on the length of the string, although it was pretty big.

Here is a portion of an agent to get the data

Dim s As New NotesSession

Dim context As NotesDocument

Set context = s.DocumentContext

Dim reqContent as String

reqContent = context.GetItemValue(“Request_Content_001”)(0)

reqContent then contains the string fieldname=value&fieldname2=value

If you lots of data the fields fill up I assume because of Notes field size limitation so you increase the number at the end of the field name until you get to 999 such as

context.GetItemValue(“Request_Content_002”)(0)

context.GetItemValue(“Request_Content_003”)(0).

I think earlier version like versions 5 of Notes only allow up to 99 fields.

Subject: -

Subject: HTTP Post and GET

Here’s a fairly comprehensive GET - I don’t use POST so can’t help you. This tries to navigate proxies as well as use the right http protocol (but it’s written specifically for Windows environment so may be limited use)

Public Function CommsWithWorld(inString As String, doc As NotesDocument) As String

Dim session As New NotesSession 

Dim rtitem As NotesRichTextItem	

Dim ws As New NotesUIWorkspace

Dim mURL As String ' string that holds the URL to be accessed 

Dim mSendBody As String ' XML body to be sent to API

Dim mHTTPResult As String ' XML that the server returns

Dim offset As Integer, returncode As Integer

Dim token  As String, XMLString As String, plaintext As String, result As String

Dim mHTTPObj As Variant

Dim urlSend As String, urlResult As Variant

Dim pac As String

Dim errFlag As Integer, status As Integer

Dim c1 As Long, c2 As Long, c3 As Long, i As Double



On Error Goto processError1



'find which HTTP protocol is installed

Try_WinHTTP51:

On Error Goto WinHTTP51_Error

Set mHTTPObj = CreateObject("WinHTTP.WinHTTPRequest.5.1")

Goto Continue_WinHTTP

Try_WinHTTP50:

On Error Goto WinHTTP5_Error

Set mHTTPObj = CreateObject("WinHTTP.WinHTTPRequest.5")

Goto Continue_WinHTTP

Try_MSXML2:

On Error Goto MsXML2_Error

Set mHTTPObj = CreateObject("MsXml2.ServerXmlHttp.6.0")

On Error Goto 0	

Continue_WinHTTP:

On Error Goto processError1

' Set Request Timeouts (recommended to be a little high, since some API requests may take  a long time to execute

mHTTPObj.SetTimeouts 15000, 15000, 15000, 15000



'get the proxy from locationDoc	

Dim db As NotesDatabase

Dim locationDoc As NotesDocument

Dim tResult As String, tresarray As Variant, tProxy As String, NAB As String

nab = session.GetEnvironmentString("NAMES",True)

If nab = "" Then nab = "names.nsf"

If Instr(nab,",") > 0 Then

	nab = Trim$(Left$(nab,Instr(nab,",")-1))

End If

Set db=New notesdatabase("",nab)

tResult = session.GetEnvironmentString( "Location",True)

tresarray = Split(tResult,",")

Set locationDoc = db.GetDocumentByID(tresarray(1))

If Not (locationDoc Is Nothing) Then 

	tProxy = locationDoc.Proxy_HTTP(0)

Else

	Messagebox "Warning: No location information in notes.ini for Proxy settings",16,IW_COMMS_ERR_1

	tProxy = ""

End If

'HTTPREQUEST_PROXYSETTING_PROXY     = 2;

If tProxy <> "" Then 

	mHTTPObj.SetProxy 2, tProxy,""

End If



mHTTPObj.Open "GET", inString

mHTTPObj.SetRequestHeader "Content-Type", "text/http"

mHTTPObj.SetRequestHeader "Accept-Charset", "windows-1252"

retry:

mHTTPObj.Send  

On Error Goto HTTP_Error

status = Val( mHTTPObj.Status)

On Error Resume Next

PAC = mHTTPObj.WinHttpDetectAutoProxyConfigUrl 

On Error Goto HTTP_Error



If status = 200 Then

  'it's ok - now handle the result

Else

  'error message - handle it

End if

Exit Proc

WinHTTP51_Error:

' failed creating WinHTTP 5.1 object, so try WinHTTP 5.0

Resume Try_WinHTTP50

WinHTTP5_Error:

' failed creating WinHTTP 5 object, so try MsXML2

Resume Try_MsXML2

processError1:

Messagebox   "CommsWithWorld 1: " + Str$(Erl)+" - "+ Error$,48,IW_COMMS_ERR_1

CommsWithICC=""

instring = "1"

Resume 	exitProc	

errh:

Msgbox  "CommsWithWorld 2: " + Str$(Erl)+" - "+ Error$,48,COMMS_ERR_1

'Msgbox domParser.log,48, LOTUS_COMMS_ERR_1

CommsWithICC=""

instring = "2"

Resume exitproc

HTTP_Error:

Messagebox  "CommsWithWorld 3: " + Cstr(Erl) + " " + Error(Err()) ,48,COMMS_ERR_1

CommsWithICC = ""

instring = "3"

Resume exitProc

Bypass_Error:

instring = "8"

Resume exitProc

MsXML2_Error:

Messagebox  "CommsWithWorld 5: " + Cstr(Err()) + " " + Error(Err()) ,48,COMMS_ERR_1	

CommsWithICC =""

instring = "5"

Resume exitProc

ObjectIntializationError1:

Messagebox "CommsWithACC 6",48,COMMS_ERR_1	

CommsWithICC =""

instring = "6"

Resume exitProc

Good luck.