My cms server (Alfresco) requires form POSTs to have the tag
enctype="multipart/form-data" (even if no files or uploads are in the
form).
Since GWT doesn't provide any methods for constructing the body/
payload of post requests, I am trying to roll my own but so far my
server isn't recognizing the data. This is not an SOP issue; I am
hitting the server successfully. Can anyone spot any errors in the
following? I have GWT.Logged the requestData and it looks correct
AFAIK based on the RFC and web articles I've read about this.
In a subclass of RequestBuilder I have:
// post body delimiters and headers:
public static final String BOUNDARY = "c0ff33";
public static final String CONTENT_DISP_LINE = "Content-disposition:
form-data; filename=\"\" name=\"";
public static final String TEXT_PLAIN = "Content-type: text/plain;
charset=utf-8";
// http headers:
public static final String CONTENT_TYPE_HEADER = "Content-type";
public static final String CONTENT_LENGTH_HEADER = "Content-
length";
public static final String CONTENT_TYPE = "multipart/form-data;
boundary="+BOUNDARY;
// builds the body of the request, and sets appropriate
headers
public void setMultipartFormData(final String key, final String
value)
{
StringBuffer body = new StringBuffer();
body.append("--" + BOUNDARY+"\n");
body.append(CONTENT_DISP_LINE+ key+"\"\n");
body.append(TEXT_PLAIN+"\n\n");
body.append(value);
body.append("\n--" + BOUNDARY+"--\n");
setHeader(CONTENT_TYPE_HEADER, CONTENT_TYPE);
setHeader(CONTENT_LENGTH_HEADER, String.valueOf(body.length()));
setRequestData(body.toString());
}
// in another class:
MyRequestBuilder rb = new MyRequestBuilder(RequestBuilder.POST, url);
rb.setMultipartFormData("json", jsonStr);
rb.setCallback(new RequestCallback() ...);
rb.send();
An alternate idea would be to have a hidden FormPanel that I setup and
let the browser do the Posting for me. However, a drawback there
would be that the FormHandler is less useful than the
RequestCallback.
Any suggestions appreciated. Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---