Gentlemen,
I have to create an agent, which fills in and posts a form on a website. I was trying to use the URLFetcher tooling as found on http://www.nsftools.com. I was trying this piece of code:
Option Public
Option Declare
Use “UrlFetcherLS”
Sub Initialize
Dim fetcher As New UrlFetcher
Dim fileName As String
Call fetcher.AddPostParam(“q”, “Ronald van Gogh” )
fileName = fetcher.getUrlAsFile(“http://www.google.com”)
’ if we successfully got the URL, say what the file name is
If (fileName <> “”) Then
Print "URL retrieved as file: " + fileName
Else
Print "There was an error: " + fetcher.getLastError()
End If
End Sub
However running this code results in the error:
There was an error: Stream closed.
Without the AddPostParam line, it works fine. Any suggestions?
Kind regards, Ronald van Gogh
Subject: Problem posting form with URLFetcher
Does the Google home page allow a POST request? The form on the home page points to “/search”, which would make the URL Google, and the form makes a GET request, not a POST.
Subject: RE: Problem posting form with URLFetcher
That’s a good one. I was automatically searching the problem on the agent site. Is there a simple way to test the functionality? Is there a public website on which I can do the post?
The problem is that other people are building the application to do the post to and that site is not available. I myself are currently located with a customer and I don’t have access to a web server to build such a page on.
Kind regards, Ronald
Subject: RE: Problem posting form with URLFetcher
You can post to your own machine using the loopback IP address 127.0.0.1 to a form that allows Anonymous to create documents:
http://127.0.0.1/somedatabase.nsf/someform?CreateDocument
The ?CreateDocument query string is necessary to ensure that the info is posted to the database.
ADDED: Don’t forget to preview something in the browser to start your local HTTP task if you are testing locally before you make the POST request.