Re: GWT: Get and Post

103 views
Skip to first unread message

Manuel Carrasco Moñino

unread,
Oct 2, 2012, 11:49:18 AM10/2/12
to google-we...@googlegroups.com
Set the action parameter in the url:

RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, "http://host/page.php?action=login");


- Manolo


On Mon, Oct 1, 2012 at 9:10 AM, Zach <zjz...@gmail.com> wrote:
Hey I'm trying to send a Get and multiple Posts to a server that then replies accordingly. The server is PHP, and handles the request the following way:

switch($_GET['action'])
{
case 'login':
$response = Account::login($_POST['username'], $_POST['password']);
break;
case 'logout':
$response = Account::logout();
break;
case 'submitChat':
$response = Chat::submitChat($_POST['room'],$_POST['message']);
break;

default:
throw new Exception('bad action');
}

basically the Get chooses what method to pick in the AJAX.php, and the Post delivers the parameters. I'm able to get this to work using HTML forms (coded manually), where clicking submit on the form sends a Get value of "login" and 2 simultaneous Post values of "usernameHere" and "password" which are then handled by AJAX correctly.

How do I do this in GWT programatically? I've found RequestBuilder.sendRequest but this seems to only either send a Get or a Post, not both, and it seems like I cannot send multiple Posts like I want to. Any small example code would be greatly appreciated! Thanks!

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/4qattmswwqUJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Joseph Lust

unread,
Oct 2, 2012, 12:31:20 PM10/2/12
to google-we...@googlegroups.com
Zach,

It is worth noting there that there are a number of "methods" in the HTTP spec:
  • GET, POST, PUT, DELETE, OPTIONS, TRACE, HEAD
The GET method is meant to only retrieve items, not to take actions as noted:
 the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval

What you are doing here is confusing what is happening. You are POSTing, not GETing AND POSTing. It is not possible to do both at once. However, the PHP globals are confusing with their $_GET and $_POST names as $_GET just has query parameters and $_POST has actual posted form fields. Just use the $_REQUEST variable and it will be less conflating as it is an aggregate of GET, POST, and COOKIE.

So, as Manuel pointed out, you can add query parameters to the URL of your POST request, but in reality you are only POSTing.

Sincerely,
Joseph 
Reply all
Reply to author
Forward
0 new messages