AnsweredAssumed Answered

Posting form data to a web script

Question asked by stiegld on Dec 22, 2007
Latest reply on Jan 17, 2008 by stiegld
Hi folks,

Happy holidays to all.

I am trying to write a webscript that accepts formdata from a form. The webapp sending the form, however, uses a commons-httpclient proxy to do authentication and to separate the alfresco instance from the web application.

I can't seem to get the web script to accept any arguments. Here is an excerpt from the webscript code:


var authorEmail = null;
var content = null;
var comment = null;

for (arg in args)
  logger.log(arg + "=" + args[arg]);

// log each argument (assuming one or more values have been provided for each)
for (arg in argsM)
  for each (val in argsM[arg])
     logger.log(arg + "=" + val);

// locate file attributes
for each (field in formdata.fields)
  if (logger.isLoggingEnabled()) {
    logger.log("found field "" with value "+field.value);
  if ( == "email")
    authorEmail = field.value;
  else if ( == "comment")
    content = field.value;

if (logger.isLoggingEnabled()) {
//    logger.log("formdata is +"formdata.fields);
   logger.log("email is "+authorEmail);
   logger.log("content is "+content);

As you can see, this excerpt simply tries to display parameters submitted, and the only output is

email is null
content is null

The commons-http client excerpt is below:


            new UsernamePasswordCredentials(username, password));
      PostMethod post = new PostMethod(url);

      post.setRequestHeader("Content-Type", "multipart/form-data");

      Part[] parts = { new StringPart("email", authorEmail),
            new StringPart("comment", comment) };
      post.setRequestEntity(new MultipartRequestEntity(parts, post

      try {
         int status = client.executeMethod(post);

         System.out.println("received status " + status);

         if (status > 299) { // there was an error
      } finally {

I've also tried to send data using NameValuePairs and the setRequestBody () method, to no avail. I know that the Content-Type is set correctly because if I change it or remove it, the formdata object is never initialized in the script.

Any ideas?