Wednesday, December 12, 2007

HttpRequest-class

Fetching Post/Get parameters with an agent isn't easy in LotusScript with inbuilt tools.

I made this simple class today as a replacement for a get-only getParameter routine I used earlier. This class should handle both get- and post-requests.

My "documentation" (something new I've been trying out) of the class:


>> Class in a text-file
(the tabs are a little off in Notepad/Wordpad, but should look correct in DD)

>> Simple demoapp

Update, 01.07.2009: A small codechange to support multi-value requests. For instance from a form with checkboxes.

Update, 30.05.2008: There was a bug in the class. If you had a parameter containing "=", the parameter value would be cut off before =. The class is updated with the fix (demoapp not updated).

Update, 25.03.2008: I've updated the class so that it should handle request_content above 64k. Read more here.

Update, 13.12.2007: I updated the class with a method to print a html-report of the request, using the docToHTML-procedure in the previous post.

Update, 25.09.2008: Added functionality to fetch cookies from a request.

14 comments:

NotesSensei said...

Does the class doe HTTPS?
You could incorporate this:
http://www.wissel.net/blog/d6plinks/SHWL-75SN42
I would be honored!
:-) stw

Tommy Valand said...

Maybe I chose a bad name for the class..?

It's intended as a simple way to fetch parameters from POST/GET requests made to NotesAgents.

With the [HttpRequest].htmlReport-method, it's also simple to have a look at what different browsers post to the server.

Also, it's LotusScript, so.. Sorry :)

NotesSensei said...
This comment has been removed by the author.
NotesSensei said...

Got me there :-)
Having only half a look the name suggested it is something (wrapped around some java) that does HTTPRequests in agents.

Name suggestion:
HTTPparameterHelper

:-) stw

Tommy Valand said...

Django, one of the bigger Python web-frameworks (comparable to Ruby On Rails in the programming language Ruby) calls their HttpRequest-handler the same (HttpRequest), so I think I'll stick to the name.

From the Domino-server's viewpoint, what the class is dealing with is a HttpRequest.

Unknown said...

A bit off-topic: have you looked at my old URL class in LotusScript? It handles the parameters in the url perfectly :-)

Tommy Valand said...

@Johan: It looks nice. The HttpRequest is designed for other needs, though.

There is a weakness in your code, btw. Where you extract the parameter value:
For i = Lbound(pairs) To Ubound(pairs)
c = Split(pairs(i), "=")
result(i, 0) = c(Lbound(c))
result(i, 1) = c(Ubound(c))
Next i

If the parameter value contains =, you only get the part before =.

Unknown said...

@Tommy: Thanks for the response! = and & are reserved characters for separating argument keys and values in the URL. So for instance, if you have an argument that is called "comment" and the value should be "Microsoft=crap", you have to encode it like: comment=Microsoft%3Dcrap
Otherwise, you can not distinguish the key/value separator from the character in the value. :-)

Tommy Valand said...

Ah.. When I look at your code again, I see that you take URL as a parameter for the constructor.

I only skimmed through the code, so I presumed you used NotesSession.DocumentContext.getItemValue( "url_query_string_decoded" )(0)

In that case, the comment field you mentioned would contain =.

My bad.. :)

Unknown said...

No problem :D It's good to see that there are active Domino bloggers out there. I've been a bit too quiet for a long time regarding Domino development.

Tommy Valand said...

I can't speak for the others, but I feel that there is little new to blog about regarding general purpose "old school" domino development.

I haven't started working with XPages yet, so I have little to share in that department.

Unknown said...

Nice job. Exactly What I was looking for. Now I can handle post request easily.

Just a comment: If I send both, get and post parameters, it seems to take post parameters only. Anyway it's ok for me.

Thank you for sharing it.

Unknown said...

I just made a couple of small modifications for my personal use. Details:

https://gist.github.com/katio/7472688

Unknown said...

Notice I don't say "old school", I prefer "classic" :)