libURLMultipartFormData formats data in the way described in rfc 1867.
libURLMultipartFormData(form data, key_1, value_1, ..., key_n, value_n)
libURLMultipartFormData(form data, array)
put empty into tForm put "http://www.someserver.com/cgi-bin/form.cgi" into tUrl put "dave" into tName put "hello" into tMessage put "<file>" & "C:/myfile.txt" into tFile if libURLMultipartFormData(tForm, "name", tName, "message", tMessage, "file", tFile) is not empty then answer it ##error else set the httpHeaders to line 1 of tForm post line 2 to -1 of tForm to url tUrl ## check the result, etc., here set the httpHeaders to empty end if
The function can be called in a number of ways depending on the parameters passed. In all cases, the first parameter must be a variable which will be filled with the form data. The function will return empty if successful, or an error message if it fails (for example, if it couldn't open a file).
When you need to supply a file as the value of a parameter, you must pass the file name preceeded by the text <file>.
In all cases, the first line of the data returned in the form data variable is the Content-Type header that must be included in the httpHeaders of the url request. Lines 2 to the end of the data is the data that must be posted to the url.
The standard way to call the function is with pairs of name/value parameters.
You can also pass in an array instead of pairs of parameters. This could be useful if there are many parts to a form. The array must be numerically indexed, and each element should contain the part name and part value, separated by a comma. So (using the above example):
put empty into tForm put "dave" into tName put "hello" into tMessage put "<file>" & "C:/myfile.txt" into tFile put "name," & tName into tArray put "message," & tMessage into tArray put "file," & tFile into tArray if libURLMultipartFormData(tForm, tArray) is not empty then answer it ##error else set the httpHeaders to line 1 of tForm post line 2 to -1 of tForm to url ## check the result, etc., here set the httpHeaders to empty end if
You can also call the function with no arguments except the form data. This will return an "empty" form. Basically, line 1 is the header, and line 2 is the final boundary mark of the form. It is of no use by itself, but it can be used with libURLMultipartFormAddPart.
See: Internet library