is HTTPRequest.asyncPost() implemented?

9 weergaven
Naar het eerste ongelezen bericht

jamesm

ongelezen,
20 mei 2006, 15:52:5820-05-2006
aan 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?

Bericht is verwijderd

Galmar

ongelezen,
31 mei 2006, 05:53:5231-05-2006
aan 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

ongelezen,
31 mei 2006, 09:54:5331-05-2006
aan 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

ongelezen,
5 jun 2006, 14:44:3605-06-2006
aan 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

ongelezen,
5 jun 2006, 15:01:4405-06-2006
aan Google Web Toolkit
<?PHP

$_POST = $_GET;

?>

:)

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

Azzah

ongelezen,
6 jun 2006, 14:51:5306-06-2006
aan 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

Allen beantwoorden
Auteur beantwoorden
Doorsturen
0 nieuwe berichten