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 <[email protected]> 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 <[email protected]> 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("?");
> >         Set<String> 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 [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.

Reply via email to