this is a class example how to receive $_POST params in PHP, in this
case, just one param, but is extensible using json objects
this is a usage example:
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, "../
test.php");
RequestFormData.PrepareRequestFormData(builder, "jsonData",
json.toString());
.... extra init ....
builder.send();
this is how to read data in PHP:
$_POST['jsonData']
this is the class:
static class RequestFormData
{
static public void PrepareRequestFormData(RequestBuilder rb, String
variableName, String contents)
{
String boundary = MakeBoundary(variableName, contents);
rb.setHeader("Content-Type", "multipart/form-data;
boundary=".concat(boundary));
rb.setHeader("Content-Length",
String.valueOf(ComputeContentLenght(boundary, variableName,
contents)));
rb.setRequestData(getRequestData(boundary, variableName, contents));
}
static private String getRequestData(String boundary, String vn,
String c)
{
String r;
r = "--";
r += boundary;
r += "\r\n";
r += "Content-Disposition: form-data; name=\"";
r += vn;
r += "\"\r\n\r\n";
r += c;
r += "\r\n--";
r += boundary;
r += "--\r\n";
return r;
}
static private int ComputeContentLenght(String boundary, String vn,
String c)
{
/* header:
--boundary\r\n
4 bytes +
strlen(boundary)
Content-Disposition: form-data; name="variableName"\r\n
41 +
strlen(variableName)
\r\n
2 bytes
contents\r\n
2 + sizeof(contents)
--boundary--\r\n
6 + strlen(boundary)
*/
return 55 + 2 * boundary.length() + c.length() + vn.length();
}
static private String MakeBoundary(String vn, String c)
{
int i;
String boundary = "Xd2Zy5fb";
do
{
i = c.indexOf(boundary);
if(i > -1)
{
char x;
x = c.charAt(i + boundary.length());
boundary += (x + 1);
}
} while(i > -1);
do
{
i = vn.indexOf(boundary);
if(i > -1)
{
char x;
x = vn.charAt(i + boundary.length());
boundary += (x + 1);
}
} while(i > -1);
return boundary;
}
}
--
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.