is HTTPRequest.asyncPost() implemented?

已查看 9 次
跳至第一个未读帖子

jamesm

未读,
2006年5月20日 15:52:582006/5/20
收件人 Google Web Toolkit
1. I am building a GWT front end for an existing PHP+MySQL application
2. Calls to HTTPRequest.asyncGet() are generally successful
3. Calls to HTTPRequest.asyncPost() never seem to send any POST data
4. My GWT code is as follows:

class ClickResponder implements ResponseTextHandler {
public void onCompletion(String responseText)
{
label.setText(responseText) ;
}
}

[...]

button.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
if(!HTTPRequest.asyncPost(
"achilles.php?f=foo",
"x=15&zoo=bear",
new ClickResponder()))
{
label.setText("button POST request failed") ;
}
}
});

5. The relevant section of achilles.php is as follows:

if (isset($_GET['f']))
{
if ($_GET['f'] == 'foo')
{
print "foo(): " . print_r($_GET, true) . print_r($_POST, true) ;
}
}

6. After compiling and deploying everything to my webserver, I get the
following result in the label:

foo(): Array ( [f] => foo ) Array ( )

7. Clearly the GET data, embedded in the URL, makes it to the PHP
script and back to my application. It appears that no POST data is
detected by the PHP script. Why is this, and what should I be doing
differently?

已删除帖子

Galmar

未读,
2006年5月31日 05:53:522006/5/31
收件人 Google Web Toolkit
The implemented asyncPost uses text content-type and not URL encoded
content-type as you are trying to post.
Here's a code that implement a url encoding post (hopefully, Google
will supply this feature soon)

public static boolean asyncFormPost(String url, String postData,
ResponseTextHandler handler) {
String moduleName = GWT.getModuleName();
return asyncFormPost(null, null, url, postData, handler,
moduleName);
}

public static native boolean asyncFormPost(String user, String pwd,
String url, String postData, ResponseTextHandler handler, String
moduleName) /*-{
var xmlHttp = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
xmlHttp = new XMLHttpRequest();
if (xmlHttp.overrideMimeType) {
xmlHttp.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!xmlHttp) {
alert('Cannot create XMLHTTP instance');
return false;
}
try {
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
if (moduleName) {
xmlHttp.setRequestHeader("X-GWTCallingModule", moduleName);
}
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {

handler.@com.google.gwt.user.client.ResponseTextHandler::onCompletion(Ljava/lang/String;)(xmlHttp.responseText);
xmlHttp = null;
}
};
xmlHttp.send(postData);
return true;
}
catch (e) {
return false;
}
}-*/;

Mr. Monster

未读,
2006年5月31日 09:54:532006/5/31
收件人 Google Web Toolkit
Bump my post
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/37eef6eaf3de80a8
to hopefuly get some attention to this issue, it definetly needs to get
addressed.

Santos

未读,
2006年6月5日 14:44:362006/6/5
收件人 Google Web Toolkit
Galmar's right, let's hope that the GWT developers put some
url-encoding functionality into this class.

But in the meantime, there's an easy server-side fix if you're using a
PHP script. Just send the POST data like a URL-encoded string (for
example "foo=bar&x=y"), then use the PHP script to parse the raw POST
data manually into your $_POST global with the parse_str function.

So just add the following line at the top of your PHP script:

parse_str( $HTTP_RAW_POST_DATA, $GLOBALS['_POST'] );

Given the the above example, this function call would set $_POST[ 'foo'
] = 'bar' and $_POST[ 'x' ] = 'y'.

Mr. Monster

未读,
2006年6月5日 15:01:442006/6/5
收件人 Google Web Toolkit
<?PHP

$_POST = $_GET;

?>

:)

That's my temporary fix untill asyncPost() with form encoding is
implemented.

Azzah

未读,
2006年6月6日 14:51:532006/6/6
收件人 Google Web Toolkit
Hi,

It should be noted that use of $_GET as above will only work in simple
cases.

There is a limit (1k ??) for the length of the GET request string.

Cheers,

Aaron Watkins
----------------------
My Site: http://www.goannatravel.com

回复全部
回复作者
转发
0 个新帖子