Re: $_POST is empty when request made using RequestBuilder

2010-07-22 Thread malrawi
Thanks everyone very nice tips and links.

Salk31 Cokol, you were right, I didn't need the ?, PHP page
wouldn't get the first parameter because of the ?

VM, nice article and very smart hack... but it got me wondering
whether I will be able to maintain status on the server (using
sessions), especially after I read the other hack on how to use the
iframe name to store information.

I am lucky that I am controlling both the PHP pages and GWT
application, and both will be running from the same domain and server,
so I tried deploying both on the same server and they communicate
perfectly with no hassle using RequestBuilder. These issues are raised
when I try to run the GWT application through Eclipse.

I could be wrong, but it seems like no matter what technique you use
to send a cross server POST request, will give you a lot of pain
especially if you are interested in maintaining status...

Thanks a bunch.
Musab


On Jul 21, 4:08 pm, cokol eplisc...@googlemail.com wrote:
 hi!

 so if you really need to go for HTTP POST rather than get, then do so,
 remove the '?' from post body, these would be required for CGI doing
 GET but not in this case.

 you dont need to go for JSNI!! SOP cannot be workarounded on the
 client solely. You have to write simple gateway service which you call
 from the client (via RequestBuilder or XMLHttpRequest) and the data is
 posted via socket from the backend to the destination server.

 also refer to this 
 howto:http://code.google.com/intl/de-DE/webtoolkit/doc/latest/FAQ_Server.ht...

 greets,

 On 21 Jul., 13:55, malrawi musab.alr...@gmail.com wrote:



  Hello Again,

  For a second I thought the I managed to solve the SOP by following and
  applying Google's tutorial found 
  inhttp://code.google.com/webtoolkit/doc/latest/tutorial/Xsite.html

  But I realized that I was doing a GET request and not a POST
  request :/
  So I guess I am back to square 1.

  I read somewhere on the net that JNSI works only for GET request... Is
  this correct?
  Is there a way to make a POST request to a PHP page (port 80) without
  violating the SOP? a link to an example or manual would be really
  great.

  Thanks again for the help and tips.
  Musab

  On Jul 20, 3:35 pm, malrawi musab.alr...@gmail.com wrote:

   Thanks Rob,
   The problem was because I wasn't encoding the URL, Now when I think
   about it, it is kind of strange because the logs show that  a request
   was sent but the only problem was with the $_POST, You would expect
   not being able to send the request if you don't encode the url and not
   send a request with no parameters.

   What was interesting too, the fact that getStatusCode() returned 0. I
   checked the group and it seems that it has something to do with SOP
   (correct me please if I am wrong). Would having the GWT application in
   the same folder as the PHP project solve this issue?
   Please, are there any other work arounds to the SOP issue?

   Thanks again
   Musab

   On Jul 19, 5:09 pm, RPB robbol...@gmail.com wrote:

Apologies if this is a double-post, the thread didn't seem to update
the first time.

I don't see anything in particular that is wrong with your code, but
the following works for me if you want to give it a try:

public void postPHPRequest(String url, String postData){
                url = URL.encode(url);
                RequestBuilder builder = new 
RequestBuilder(RequestBuilder.POST,
url);

            try {
              builder.setHeader(Content-Type, application/x-www-form-
urlencoded);
              @SuppressWarnings(unused)
             Requestreq = builder.sendRequest(postData, new
RequestCallback() {

                public void onError(Requestrequest, Throwable 
exception) {
                        fireErrorEvent(Failed to send therequest:  +
exception.getMessage());
                }

                public void onResponseReceived(Requestrequest, Response
response) {
                  String output = response.getText();

                }
              });
            } catch (RequestException e) {
                fireErrorEvent(Failed to send therequest:  + 
e.getMessage());
            }
        }

You can look at 'output' which should display any echos you have in
your PHP. Hopefully this will help you debug out what is happening.
If this doesn't work check that you are not violating the SOP (same
origin policy). There are other threads on this forum with more info
on this.

Good luck,
Rob

On Jul 18, 1:44 pm, malrawi musab.alr...@gmail.com wrote:

 Hi,
 I am really new to GWT, I tried searching the net for hours to get an
 answer to my problem with no luck. Here is what I am doing:
 I am creating a simple EntryPoint which shows some text fields, when
 the user clicks on a button I want to send aPOSTrequestto a php
 page. The PHP page says that 

Re: $_POST is empty when request made using RequestBuilder

2010-07-21 Thread malrawi
Hello Again,

For a second I thought the I managed to solve the SOP by following and
applying Google's tutorial found in
http://code.google.com/webtoolkit/doc/latest/tutorial/Xsite.html

But I realized that I was doing a GET request and not a POST
request :/
So I guess I am back to square 1.

I read somewhere on the net that JNSI works only for GET request... Is
this correct?
Is there a way to make a POST request to a PHP page (port 80) without
violating the SOP? a link to an example or manual would be really
great.

Thanks again for the help and tips.
Musab


On Jul 20, 3:35 pm, malrawi musab.alr...@gmail.com wrote:
 Thanks Rob,
 The problem was because I wasn't encoding the URL, Now when I think
 about it, it is kind of strange because the logs show that  a request
 was sent but the only problem was with the $_POST, You would expect
 not being able to send the request if you don't encode the url and not
 send a request with no parameters.

 What was interesting too, the fact that getStatusCode() returned 0. I
 checked the group and it seems that it has something to do with SOP
 (correct me please if I am wrong). Would having the GWT application in
 the same folder as the PHP project solve this issue?
 Please, are there any other work arounds to the SOP issue?

 Thanks again
 Musab

 On Jul 19, 5:09 pm, RPB robbol...@gmail.com wrote:



  Apologies if this is a double-post, the thread didn't seem to update
  the first time.

  I don't see anything in particular that is wrong with your code, but
  the following works for me if you want to give it a try:

  public void postPHPRequest(String url, String postData){
                  url = URL.encode(url);
                  RequestBuilder builder = new 
  RequestBuilder(RequestBuilder.POST,
  url);

              try {
                builder.setHeader(Content-Type, application/x-www-form-
  urlencoded);
                @SuppressWarnings(unused)
               Requestreq = builder.sendRequest(postData, new
  RequestCallback() {

                  public void onError(Requestrequest, Throwable exception) {
                          fireErrorEvent(Failed to send therequest:  +
  exception.getMessage());
                  }

                  public void onResponseReceived(Requestrequest, Response
  response) {
                    String output = response.getText();

                  }
                });
              } catch (RequestException e) {
                  fireErrorEvent(Failed to send therequest:  + 
  e.getMessage());
              }
          }

  You can look at 'output' which should display any echos you have in
  your PHP. Hopefully this will help you debug out what is happening.
  If this doesn't work check that you are not violating the SOP (same
  origin policy). There are other threads on this forum with more info
  on this.

  Good luck,
  Rob

  On Jul 18, 1:44 pm, malrawi musab.alr...@gmail.com wrote:

   Hi,
   I am really new to GWT, I tried searching the net for hours to get an
   answer to my problem with no luck. Here is what I am doing:
   I am creating a simple EntryPoint which shows some text fields, when
   the user clicks on a button I want to send aPOSTrequestto a php
   page. The PHP page says that myrequestparameters are not set.
   Right before I send therequestI display therequestdata and they
   look right. As the code shows, I am setting the content type, I am
   appending the parameters properly, I don't know what is wrong.

   I didn't want to use FormPanel because it seemed like I wouldn't be
   able to send arequestasynchronously (correct me if I am wrong, my
   conclusion was based on Javadoc's examples also some examples on the
   net)

   Here is the code:

   RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
   builder.setHeader(Content-type, application/x-www-form-
   urlencoded);
   StringBuffer requestData = new StringBuffer();

   // parameters is a HashMap
   if (parameters != null ){
           requestData.append(?);
           SetString keys = parameters.keySet();
           for (String key : keys ){
                   requestData.append(URL.encode(key));
                   requestData.append(=);
                   requestData.append(URL.encode(parameters.get(key)));
                   requestData.append();
           }

   }

   try {
           Window.alert(requestData.toString());
           builder.sendRequest(requestData.toString(), handler);} catch ( 
   Exception e){

           Window.alert(e.getMessage());

   }

   Please help.

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: $_POST is empty when request made using RequestBuilder

2010-07-21 Thread V M
Got this from old thread :

http://development.lombardi.com/?p=611

I hope it helps.

-VM
On Wed, Jul 21, 2010 at 7:55 AM, malrawi musab.alr...@gmail.com wrote:

 Hello Again,

 For a second I thought the I managed to solve the SOP by following and
 applying Google's tutorial found in
 http://code.google.com/webtoolkit/doc/latest/tutorial/Xsite.html

 But I realized that I was doing a GET request and not a POST
 request :/
 So I guess I am back to square 1.

 I read somewhere on the net that JNSI works only for GET request... Is
 this correct?
 Is there a way to make a POST request to a PHP page (port 80) without
 violating the SOP? a link to an example or manual would be really
 great.

 Thanks again for the help and tips.
 Musab


 On Jul 20, 3:35 pm, malrawi musab.alr...@gmail.com wrote:
  Thanks Rob,
  The problem was because I wasn't encoding the URL, Now when I think
  about it, it is kind of strange because the logs show that  a request
  was sent but the only problem was with the $_POST, You would expect
  not being able to send the request if you don't encode the url and not
  send a request with no parameters.
 
  What was interesting too, the fact that getStatusCode() returned 0. I
  checked the group and it seems that it has something to do with SOP
  (correct me please if I am wrong). Would having the GWT application in
  the same folder as the PHP project solve this issue?
  Please, are there any other work arounds to the SOP issue?
 
  Thanks again
  Musab
 
  On Jul 19, 5:09 pm, RPB robbol...@gmail.com wrote:
 
 
 
   Apologies if this is a double-post, the thread didn't seem to update
   the first time.
 
   I don't see anything in particular that is wrong with your code, but
   the following works for me if you want to give it a try:
 
   public void postPHPRequest(String url, String postData){
   url = URL.encode(url);
   RequestBuilder builder = new
 RequestBuilder(RequestBuilder.POST,
   url);
 
   try {
 builder.setHeader(Content-Type,
 application/x-www-form-
   urlencoded);
 @SuppressWarnings(unused)
Requestreq = builder.sendRequest(postData, new
   RequestCallback() {
 
   public void onError(Requestrequest, Throwable
 exception) {
   fireErrorEvent(Failed to send therequest:  +
   exception.getMessage());
   }
 
   public void onResponseReceived(Requestrequest, Response
   response) {
 String output = response.getText();
 
   }
 });
   } catch (RequestException e) {
   fireErrorEvent(Failed to send therequest:  +
 e.getMessage());
   }
   }
 
   You can look at 'output' which should display any echos you have in
   your PHP. Hopefully this will help you debug out what is happening.
   If this doesn't work check that you are not violating the SOP (same
   origin policy). There are other threads on this forum with more info
   on this.
 
   Good luck,
   Rob
 
   On Jul 18, 1:44 pm, malrawi musab.alr...@gmail.com wrote:
 
Hi,
I am really new to GWT, I tried searching the net for hours to get an
answer to my problem with no luck. Here is what I am doing:
I am creating a simple EntryPoint which shows some text fields, when
the user clicks on a button I want to send aPOSTrequestto a php
page. The PHP page says that myrequestparameters are not set.
Right before I send therequestI display therequestdata and they
look right. As the code shows, I am setting the content type, I am
appending the parameters properly, I don't know what is wrong.
 
I didn't want to use FormPanel because it seemed like I wouldn't be
able to send arequestasynchronously (correct me if I am wrong, my
conclusion was based on Javadoc's examples also some examples on the
net)
 
Here is the code:
 
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
 url);
builder.setHeader(Content-type, application/x-www-form-
urlencoded);
StringBuffer requestData = new StringBuffer();
 
// parameters is a HashMap
if (parameters != null ){
requestData.append(?);
SetString keys = parameters.keySet();
for (String key : keys ){
requestData.append(URL.encode(key));
requestData.append(=);
requestData.append(URL.encode(parameters.get(key)));
requestData.append();
}
 
}
 
try {
Window.alert(requestData.toString());
builder.sendRequest(requestData.toString(), handler);} catch
 ( Exception e){
 
Window.alert(e.getMessage());
 
}
 
Please help.

 --
 You received this message because you are subscribed to the Google Groups
 Google Web Toolkit group.
 To post to this group, send email to 

Re: $_POST is empty when request made using RequestBuilder

2010-07-21 Thread cokol
hi!

so if you really need to go for HTTP POST rather than get, then do so,
remove the '?' from post body, these would be required for CGI doing
GET but not in this case.

you dont need to go for JSNI!! SOP cannot be workarounded on the
client solely. You have to write simple gateway service which you call
from the client (via RequestBuilder or XMLHttpRequest) and the data is
posted via socket from the backend to the destination server.

also refer to this howto:
http://code.google.com/intl/de-DE/webtoolkit/doc/latest/FAQ_Server.html#How_can_I_dynamically_fetch_JSON_feeds_from_other_web_domains

greets,


On 21 Jul., 13:55, malrawi musab.alr...@gmail.com wrote:
 Hello Again,

 For a second I thought the I managed to solve the SOP by following and
 applying Google's tutorial found 
 inhttp://code.google.com/webtoolkit/doc/latest/tutorial/Xsite.html

 But I realized that I was doing a GET request and not a POST
 request :/
 So I guess I am back to square 1.

 I read somewhere on the net that JNSI works only for GET request... Is
 this correct?
 Is there a way to make a POST request to a PHP page (port 80) without
 violating the SOP? a link to an example or manual would be really
 great.

 Thanks again for the help and tips.
 Musab

 On Jul 20, 3:35 pm, malrawi musab.alr...@gmail.com wrote:



  Thanks Rob,
  The problem was because I wasn't encoding the URL, Now when I think
  about it, it is kind of strange because the logs show that  a request
  was sent but the only problem was with the $_POST, You would expect
  not being able to send the request if you don't encode the url and not
  send a request with no parameters.

  What was interesting too, the fact that getStatusCode() returned 0. I
  checked the group and it seems that it has something to do with SOP
  (correct me please if I am wrong). Would having the GWT application in
  the same folder as the PHP project solve this issue?
  Please, are there any other work arounds to the SOP issue?

  Thanks again
  Musab

  On Jul 19, 5:09 pm, RPB robbol...@gmail.com wrote:

   Apologies if this is a double-post, the thread didn't seem to update
   the first time.

   I don't see anything in particular that is wrong with your code, but
   the following works for me if you want to give it a try:

   public void postPHPRequest(String url, String postData){
                   url = URL.encode(url);
                   RequestBuilder builder = new 
   RequestBuilder(RequestBuilder.POST,
   url);

               try {
                 builder.setHeader(Content-Type, application/x-www-form-
   urlencoded);
                 @SuppressWarnings(unused)
                Requestreq = builder.sendRequest(postData, new
   RequestCallback() {

                   public void onError(Requestrequest, Throwable exception) {
                           fireErrorEvent(Failed to send therequest:  +
   exception.getMessage());
                   }

                   public void onResponseReceived(Requestrequest, Response
   response) {
                     String output = response.getText();

                   }
                 });
               } catch (RequestException e) {
                   fireErrorEvent(Failed to send therequest:  + 
   e.getMessage());
               }
           }

   You can look at 'output' which should display any echos you have in
   your PHP. Hopefully this will help you debug out what is happening.
   If this doesn't work check that you are not violating the SOP (same
   origin policy). There are other threads on this forum with more info
   on this.

   Good luck,
   Rob

   On Jul 18, 1:44 pm, malrawi musab.alr...@gmail.com wrote:

Hi,
I am really new to GWT, I tried searching the net for hours to get an
answer to my problem with no luck. Here is what I am doing:
I am creating a simple EntryPoint which shows some text fields, when
the user clicks on a button I want to send aPOSTrequestto a php
page. The PHP page says that myrequestparameters are not set.
Right before I send therequestI display therequestdata and they
look right. As the code shows, I am setting the content type, I am
appending the parameters properly, I don't know what is wrong.

I didn't want to use FormPanel because it seemed like I wouldn't be
able to send arequestasynchronously (correct me if I am wrong, my
conclusion was based on Javadoc's examples also some examples on the
net)

Here is the code:

RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
builder.setHeader(Content-type, application/x-www-form-
urlencoded);
StringBuffer requestData = new StringBuffer();

// parameters is a HashMap
if (parameters != null ){
        requestData.append(?);
        SetString keys = parameters.keySet();
        for (String key : keys ){
                requestData.append(URL.encode(key));
                requestData.append(=);
                

Re: $_POST is empty when request made using RequestBuilder

2010-07-21 Thread cokol
btw:

you can of course abuse HTML resource reference tags allowing SOP
( like SCRIPT, IMG, IFRAME ) but they all do only support HTTP GET. If
your service you gonna talk with requires HTTP POST, there is no other
way

you can also patch your DNS but this is for sure not the way you look
for...

best,


On 21 Jul., 13:55, malrawi musab.alr...@gmail.com wrote:
 Hello Again,

 For a second I thought the I managed to solve the SOP by following and
 applying Google's tutorial found 
 inhttp://code.google.com/webtoolkit/doc/latest/tutorial/Xsite.html

 But I realized that I was doing a GET request and not a POST
 request :/
 So I guess I am back to square 1.

 I read somewhere on the net that JNSI works only for GET request... Is
 this correct?
 Is there a way to make a POST request to a PHP page (port 80) without
 violating the SOP? a link to an example or manual would be really
 great.

 Thanks again for the help and tips.
 Musab

 On Jul 20, 3:35 pm, malrawi musab.alr...@gmail.com wrote:



  Thanks Rob,
  The problem was because I wasn't encoding the URL, Now when I think
  about it, it is kind of strange because the logs show that  a request
  was sent but the only problem was with the $_POST, You would expect
  not being able to send the request if you don't encode the url and not
  send a request with no parameters.

  What was interesting too, the fact that getStatusCode() returned 0. I
  checked the group and it seems that it has something to do with SOP
  (correct me please if I am wrong). Would having the GWT application in
  the same folder as the PHP project solve this issue?
  Please, are there any other work arounds to the SOP issue?

  Thanks again
  Musab

  On Jul 19, 5:09 pm, RPB robbol...@gmail.com wrote:

   Apologies if this is a double-post, the thread didn't seem to update
   the first time.

   I don't see anything in particular that is wrong with your code, but
   the following works for me if you want to give it a try:

   public void postPHPRequest(String url, String postData){
                   url = URL.encode(url);
                   RequestBuilder builder = new 
   RequestBuilder(RequestBuilder.POST,
   url);

               try {
                 builder.setHeader(Content-Type, application/x-www-form-
   urlencoded);
                 @SuppressWarnings(unused)
                Requestreq = builder.sendRequest(postData, new
   RequestCallback() {

                   public void onError(Requestrequest, Throwable exception) {
                           fireErrorEvent(Failed to send therequest:  +
   exception.getMessage());
                   }

                   public void onResponseReceived(Requestrequest, Response
   response) {
                     String output = response.getText();

                   }
                 });
               } catch (RequestException e) {
                   fireErrorEvent(Failed to send therequest:  + 
   e.getMessage());
               }
           }

   You can look at 'output' which should display any echos you have in
   your PHP. Hopefully this will help you debug out what is happening.
   If this doesn't work check that you are not violating the SOP (same
   origin policy). There are other threads on this forum with more info
   on this.

   Good luck,
   Rob

   On Jul 18, 1:44 pm, malrawi musab.alr...@gmail.com wrote:

Hi,
I am really new to GWT, I tried searching the net for hours to get an
answer to my problem with no luck. Here is what I am doing:
I am creating a simple EntryPoint which shows some text fields, when
the user clicks on a button I want to send aPOSTrequestto a php
page. The PHP page says that myrequestparameters are not set.
Right before I send therequestI display therequestdata and they
look right. As the code shows, I am setting the content type, I am
appending the parameters properly, I don't know what is wrong.

I didn't want to use FormPanel because it seemed like I wouldn't be
able to send arequestasynchronously (correct me if I am wrong, my
conclusion was based on Javadoc's examples also some examples on the
net)

Here is the code:

RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
builder.setHeader(Content-type, application/x-www-form-
urlencoded);
StringBuffer requestData = new StringBuffer();

// parameters is a HashMap
if (parameters != null ){
        requestData.append(?);
        SetString keys = parameters.keySet();
        for (String key : keys ){
                requestData.append(URL.encode(key));
                requestData.append(=);
                requestData.append(URL.encode(parameters.get(key)));
                requestData.append();
        }

}

try {
        Window.alert(requestData.toString());
        builder.sendRequest(requestData.toString(), handler);} catch ( 
Exception e){

        Window.alert(e.getMessage());

}


Re: $_POST is empty when request made using RequestBuilder

2010-07-20 Thread malrawi
Thanks Rob,

The problem was because I wasn't encoding the URL. Wired, I would
expect the whole request to fail if I don't encode the URL.

Another thing, I received 0 (zero) as status code, i checked the
forums and it seems that it is related to SOP as you suspected. Would
having the PHP files in the same www folder as the GWT application
solve this issue?
Are there any workarounds to SOP?

Apologies if my post is a duplicate but I am facing what Rob faced,
the thread is not updated.

Thanks again
Musab


On Jul 19, 5:09 pm, RPB robbol...@gmail.com wrote:
 Apologies if this is a double-post, the thread didn't seem to update
 the first time.

 I don't see anything in particular that is wrong with your code, but
 the following works for me if you want to give it a try:

 public void postPHPRequest(String url, String postData){
                 url = URL.encode(url);
                 RequestBuilder builder = new 
 RequestBuilder(RequestBuilder.POST,
 url);

             try {
               builder.setHeader(Content-Type, application/x-www-form-
 urlencoded);
               @SuppressWarnings(unused)
              Requestreq = builder.sendRequest(postData, new
 RequestCallback() {

                 public void onError(Requestrequest, Throwable exception) {
                         fireErrorEvent(Failed to send therequest:  +
 exception.getMessage());
                 }

                 public void onResponseReceived(Requestrequest, Response
 response) {
                   String output = response.getText();

                 }
               });
             } catch (RequestException e) {
                 fireErrorEvent(Failed to send therequest:  + 
 e.getMessage());
             }
         }

 You can look at 'output' which should display any echos you have in
 your PHP. Hopefully this will help you debug out what is happening.
 If this doesn't work check that you are not violating the SOP (same
 origin policy). There are other threads on this forum with more info
 on this.

 Good luck,
 Rob

 On Jul 18, 1:44 pm, malrawi musab.alr...@gmail.com wrote:



  Hi,
  I am really new to GWT, I tried searching the net for hours to get an
  answer to my problem with no luck. Here is what I am doing:
  I am creating a simple EntryPoint which shows some text fields, when
  the user clicks on a button I want to send aPOSTrequestto a php
  page. The PHP page says that myrequestparameters are not set.
  Right before I send therequestI display therequestdata and they
  look right. As the code shows, I am setting the content type, I am
  appending the parameters properly, I don't know what is wrong.

  I didn't want to use FormPanel because it seemed like I wouldn't be
  able to send arequestasynchronously (correct me if I am wrong, my
  conclusion was based on Javadoc's examples also some examples on the
  net)

  Here is the code:

  RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
  builder.setHeader(Content-type, application/x-www-form-
  urlencoded);
  StringBuffer requestData = new StringBuffer();

  // parameters is a HashMap
  if (parameters != null ){
          requestData.append(?);
          SetString keys = parameters.keySet();
          for (String key : keys ){
                  requestData.append(URL.encode(key));
                  requestData.append(=);
                  requestData.append(URL.encode(parameters.get(key)));
                  requestData.append();
          }

  }

  try {
          Window.alert(requestData.toString());
          builder.sendRequest(requestData.toString(), handler);} catch ( 
  Exception e){

          Window.alert(e.getMessage());

  }

  Please help.

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: $_POST is empty when request made using RequestBuilder

2010-07-20 Thread salk31
Do you need the ? ?

Maybe worth using firebug to look at what the browser is actually
sending?

On Jul 18, 1:44 pm, malrawi musab.alr...@gmail.com wrote:
 Hi,
 I am really new to GWT, I tried searching the net for hours to get an
 answer to my problem with no luck. Here is what I am doing:
 I am creating a simple EntryPoint which shows some text fields, when
 the user clicks on a button I want to send a POST request to a php
 page. The PHP page says that my request parameters are not set.
 Right before I send the request I display the request data and they
 look right. As the code shows, I am setting the content type, I am
 appending the parameters properly, I don't know what is wrong.

 I didn't want to use FormPanel because it seemed like I wouldn't be
 able to send a request asynchronously (correct me if I am wrong, my
 conclusion was based on Javadoc's examples also some examples on the
 net)

 Here is the code:

 RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
 builder.setHeader(Content-type, application/x-www-form-
 urlencoded);
 StringBuffer requestData = new StringBuffer();

 // parameters is a HashMap
 if (parameters != null ){
         requestData.append(?);
         SetString keys = parameters.keySet();
         for (String key : keys ){
                 requestData.append(URL.encode(key));
                 requestData.append(=);
                 requestData.append(URL.encode(parameters.get(key)));
                 requestData.append();
         }

 }

 try {
         Window.alert(requestData.toString());
         builder.sendRequest(requestData.toString(), handler);} catch ( 
 Exception e){

         Window.alert(e.getMessage());

 }

 Please help.

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: $_POST is empty when request made using RequestBuilder

2010-07-20 Thread salk31
Do you need that ? at the start? Just guessing.

Maybe debug with firebug? Very nice HTTP snooping...

On Jul 18, 1:44 pm, malrawi musab.alr...@gmail.com wrote:
 Hi,
 I am really new to GWT, I tried searching the net for hours to get an
 answer to my problem with no luck. Here is what I am doing:
 I am creating a simple EntryPoint which shows some text fields, when
 the user clicks on a button I want to send a POST request to a php
 page. The PHP page says that my request parameters are not set.
 Right before I send the request I display the request data and they
 look right. As the code shows, I am setting the content type, I am
 appending the parameters properly, I don't know what is wrong.

 I didn't want to use FormPanel because it seemed like I wouldn't be
 able to send a request asynchronously (correct me if I am wrong, my
 conclusion was based on Javadoc's examples also some examples on the
 net)

 Here is the code:

 RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
 builder.setHeader(Content-type, application/x-www-form-
 urlencoded);
 StringBuffer requestData = new StringBuffer();

 // parameters is a HashMap
 if (parameters != null ){
         requestData.append(?);
         SetString keys = parameters.keySet();
         for (String key : keys ){
                 requestData.append(URL.encode(key));
                 requestData.append(=);
                 requestData.append(URL.encode(parameters.get(key)));
                 requestData.append();
         }

 }

 try {
         Window.alert(requestData.toString());
         builder.sendRequest(requestData.toString(), handler);} catch ( 
 Exception e){

         Window.alert(e.getMessage());

 }

 Please help.

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: $_POST is empty when request made using RequestBuilder

2010-07-20 Thread malrawi
Thanks Rob,
The problem was because I wasn't encoding the URL, Now when I think
about it, it is kind of strange because the logs show that  a request
was sent but the only problem was with the $_POST, You would expect
not being able to send the request if you don't encode the url and not
send a request with no parameters.

What was interesting too, the fact that getStatusCode() returned 0. I
checked the group and it seems that it has something to do with SOP
(correct me please if I am wrong). Would having the GWT application in
the same folder as the PHP project solve this issue?
Please, are there any other work arounds to the SOP issue?

Thanks again
Musab

On Jul 19, 5:09 pm, RPB robbol...@gmail.com wrote:
 Apologies if this is a double-post, the thread didn't seem to update
 the first time.

 I don't see anything in particular that is wrong with your code, but
 the following works for me if you want to give it a try:

 public void postPHPRequest(String url, String postData){
                 url = URL.encode(url);
                 RequestBuilder builder = new 
 RequestBuilder(RequestBuilder.POST,
 url);

             try {
               builder.setHeader(Content-Type, application/x-www-form-
 urlencoded);
               @SuppressWarnings(unused)
              Requestreq = builder.sendRequest(postData, new
 RequestCallback() {

                 public void onError(Requestrequest, Throwable exception) {
                         fireErrorEvent(Failed to send therequest:  +
 exception.getMessage());
                 }

                 public void onResponseReceived(Requestrequest, Response
 response) {
                   String output = response.getText();

                 }
               });
             } catch (RequestException e) {
                 fireErrorEvent(Failed to send therequest:  + 
 e.getMessage());
             }
         }

 You can look at 'output' which should display any echos you have in
 your PHP. Hopefully this will help you debug out what is happening.
 If this doesn't work check that you are not violating the SOP (same
 origin policy). There are other threads on this forum with more info
 on this.

 Good luck,
 Rob

 On Jul 18, 1:44 pm, malrawi musab.alr...@gmail.com wrote:



  Hi,
  I am really new to GWT, I tried searching the net for hours to get an
  answer to my problem with no luck. Here is what I am doing:
  I am creating a simple EntryPoint which shows some text fields, when
  the user clicks on a button I want to send aPOSTrequestto a php
  page. The PHP page says that myrequestparameters are not set.
  Right before I send therequestI display therequestdata and they
  look right. As the code shows, I am setting the content type, I am
  appending the parameters properly, I don't know what is wrong.

  I didn't want to use FormPanel because it seemed like I wouldn't be
  able to send arequestasynchronously (correct me if I am wrong, my
  conclusion was based on Javadoc's examples also some examples on the
  net)

  Here is the code:

  RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
  builder.setHeader(Content-type, application/x-www-form-
  urlencoded);
  StringBuffer requestData = new StringBuffer();

  // parameters is a HashMap
  if (parameters != null ){
          requestData.append(?);
          SetString keys = parameters.keySet();
          for (String key : keys ){
                  requestData.append(URL.encode(key));
                  requestData.append(=);
                  requestData.append(URL.encode(parameters.get(key)));
                  requestData.append();
          }

  }

  try {
          Window.alert(requestData.toString());
          builder.sendRequest(requestData.toString(), handler);} catch ( 
  Exception e){

          Window.alert(e.getMessage());

  }

  Please help.

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: $_POST is empty when request made using RequestBuilder

2010-07-19 Thread RPB
Apologies if this is a double-post, the thread didn't seem to update
the first time.

I don't see anything in particular that is wrong with your code, but
the following works for me if you want to give it a try:

public void postPHPRequest(String url, String postData){
url = URL.encode(url);
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
url);

try {
  builder.setHeader(Content-Type, application/x-www-form-
urlencoded);
  @SuppressWarnings(unused)
  Request req = builder.sendRequest(postData, new
RequestCallback() {

public void onError(Request request, Throwable exception) {
fireErrorEvent(Failed to send the request:  +
exception.getMessage());
}

public void onResponseReceived(Request request, Response
response) {
  String output = response.getText();

}
  });
} catch (RequestException e) {
fireErrorEvent(Failed to send the request:  + e.getMessage());
}
}

You can look at 'output' which should display any echos you have in
your PHP. Hopefully this will help you debug out what is happening.
If this doesn't work check that you are not violating the SOP (same
origin policy). There are other threads on this forum with more info
on this.

Good luck,
Rob

On Jul 18, 1:44 pm, malrawi musab.alr...@gmail.com wrote:
 Hi,
 I am really new to GWT, I tried searching the net for hours to get an
 answer to my problem with no luck. Here is what I am doing:
 I am creating a simple EntryPoint which shows some text fields, when
 the user clicks on a button I want to send a POST request to a php
 page. The PHP page says that my request parameters are not set.
 Right before I send the request I display the request data and they
 look right. As the code shows, I am setting the content type, I am
 appending the parameters properly, I don't know what is wrong.

 I didn't want to use FormPanel because it seemed like I wouldn't be
 able to send a request asynchronously (correct me if I am wrong, my
 conclusion was based on Javadoc's examples also some examples on the
 net)

 Here is the code:

 RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
 builder.setHeader(Content-type, application/x-www-form-
 urlencoded);
 StringBuffer requestData = new StringBuffer();

 // parameters is a HashMap
 if (parameters != null ){
         requestData.append(?);
         SetString keys = parameters.keySet();
         for (String key : keys ){
                 requestData.append(URL.encode(key));
                 requestData.append(=);
                 requestData.append(URL.encode(parameters.get(key)));
                 requestData.append();
         }

 }

 try {
         Window.alert(requestData.toString());
         builder.sendRequest(requestData.toString(), handler);} catch ( 
 Exception e){

         Window.alert(e.getMessage());

 }

 Please help.

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: $_POST is empty when request made using RequestBuilder

2010-07-19 Thread Thomas Broyer


On 18 juil, 14:44, malrawi musab.alr...@gmail.com wrote:
 Hi,
 I am really new to GWT, I tried searching the net for hours to get an
 answer to my problem with no luck. Here is what I am doing:
 I am creating a simple EntryPoint which shows some text fields, when
 the user clicks on a button I want to send a POST request to a php
 page. The PHP page says that my request parameters are not set.
 Right before I send the request I display the request data and they
 look right. As the code shows, I am setting the content type, I am
 appending the parameters properly, I don't know what is wrong.

 I didn't want to use FormPanel because it seemed like I wouldn't be
 able to send a request asynchronously (correct me if I am wrong, my
 conclusion was based on Javadoc's examples also some examples on the
 net)

 Here is the code:

 RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
 builder.setHeader(Content-type, application/x-www-form-
 urlencoded);
 StringBuffer requestData = new StringBuffer();

 // parameters is a HashMap
 if (parameters != null ){
         requestData.append(?);

What's this last line for?

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: $_POST is empty when request made using RequestBuilder

2010-07-19 Thread RPB
Although I can't see anything obviously incorrect with your code, the
following code snippet successfully sends a POST request in my code:

public void postPHPRequest(String url, String postData){
url = URL.encode(url);
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
url);

try {
  builder.setHeader(Content-Type, application/x-www-form-
urlencoded);

  @SuppressWarnings(unused)
  Request req = builder.sendRequest(postData, new
RequestCallback() {

public void onError(Request request, Throwable exception) {
fireErrorEvent(Failed to send the request:  +
exception.getMessage());
}

public void onResponseReceived(Request request, Response
response) {
  String output = response.getText();

}
  });
} catch (RequestException e) {
fireErrorEvent(Failed to send the request:  + e.getMessage());
}
}

You can look at the content of 'output', which should display any
echo's in your php code.

If you still have no luck, check that you are not violating the rules
of the SOP.

Good luck,
Rob

On Jul 18, 1:44 pm, malrawi musab.alr...@gmail.com wrote:
 Hi,
 I am really new to GWT, I tried searching the net for hours to get an
 answer to my problem with no luck. Here is what I am doing:
 I am creating a simple EntryPoint which shows some text fields, when
 the user clicks on a button I want to send a POST request to a php
 page. The PHP page says that my request parameters are not set.
 Right before I send the request I display the request data and they
 look right. As the code shows, I am setting the content type, I am
 appending the parameters properly, I don't know what is wrong.

 I didn't want to use FormPanel because it seemed like I wouldn't be
 able to send a request asynchronously (correct me if I am wrong, my
 conclusion was based on Javadoc's examples also some examples on the
 net)

 Here is the code:

 RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
 builder.setHeader(Content-type, application/x-www-form-
 urlencoded);
 StringBuffer requestData = new StringBuffer();

 // parameters is a HashMap
 if (parameters != null ){
         requestData.append(?);
         SetString keys = parameters.keySet();
         for (String key : keys ){
                 requestData.append(URL.encode(key));
                 requestData.append(=);
                 requestData.append(URL.encode(parameters.get(key)));
                 requestData.append();
         }

 }

 try {
         Window.alert(requestData.toString());
         builder.sendRequest(requestData.toString(), handler);} catch ( 
 Exception e){

         Window.alert(e.getMessage());

 }

 Please help.

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



$_POST is empty when request made using RequestBuilder

2010-07-18 Thread malrawi
Hi,
I am really new to GWT, I tried searching the net for hours to get an
answer to my problem with no luck. Here is what I am doing:
I am creating a simple EntryPoint which shows some text fields, when
the user clicks on a button I want to send a POST request to a php
page. The PHP page says that my request parameters are not set.
Right before I send the request I display the request data and they
look right. As the code shows, I am setting the content type, I am
appending the parameters properly, I don't know what is wrong.

I didn't want to use FormPanel because it seemed like I wouldn't be
able to send a request asynchronously (correct me if I am wrong, my
conclusion was based on Javadoc's examples also some examples on the
net)

Here is the code:

RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
builder.setHeader(Content-type, application/x-www-form-
urlencoded);
StringBuffer requestData = new StringBuffer();

// parameters is a HashMap
if (parameters != null ){
requestData.append(?);
SetString keys = parameters.keySet();
for (String key : keys ){
requestData.append(URL.encode(key));
requestData.append(=);
requestData.append(URL.encode(parameters.get(key)));
requestData.append();
}
}

try {
Window.alert(requestData.toString());
builder.sendRequest(requestData.toString(), handler);
} catch ( Exception e){
Window.alert(e.getMessage());
}

Please help.

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.