8 Replies Latest reply on Jun 5, 2009 4:02 PM by genxsol

    how to pass parameters in http post as a form data

    genxsol

      Hi Experts,


      i am trying a post request with some parameters as form data keys[email],keys[password] and message[title] but flex builder gives me error message of undefined property on each parameter below.

       

       

      request.url = "http://www.domain/create.xml";
                  var variables:URLVariables = new URLVariables();
                  variables.keys[email]="test@hotmail.com";
                  variables.keys[password]="tes";
                  variables.message[title]="Title Flex";
                  request.data=variables;
                  request.method = URLRequestMethod.POST;

       

                  var loader:URLLoader = new URLLoader();
                 
                      try
                      {
                          loader.load(request);
                          trace(loader.data);
                      }
                      catch (error:ArgumentError)
                      {
                          trace("An ArgumentError has occurred.");
                      }
                      catch (error:SecurityError)
                      {
                          trace("A SecurityError has occurred.");
                      }    

       

      /////////////////////////////////////////////////////////////////////////////

       

       

      any solution?

        • 1. Re: how to pass parameters in http post as a form data
          BennyBeta Level 4

          The URLVariables class doesn't have keys or message properties.

           

          Try something like this instead:


          variables["keys_email"] = "...";

          variables["keys_password"] = "...";

          variables["message_title"] = "...";

           

          Does that help at all?

           

          Ben Edwards

          • 2. Re: how to pass parameters in http post as a form data
            genxsol Level 1

            yes this seems fine but my program still doesn't run.

             

             

             

            i need to set mandatory header user_agent

             

             

             

            var header1:URLRequestHeader = new URLRequestHeader("user_agent", "SLEEPY-cast/1.2 OS:android/2.1");

             

             

             

            request.requestHeaders.push(header1);

             

             

             

            but it gives me ArgumentError.

             

             

             

            i think AS3 doesn't like user_agent header, if i change user_agent to any other name then no ArgumentError.

             

            any solution plz

             

             

             

            Date: Fri, 5 Jun 2009 09:06:27 -0600

            From: forums@adobe.com

            To: mr.zeeshan@hotmail.com

            Subject: how to pass parameters in http post as a form data

             

            The URLVariables class doesn't have keys or message properties.

             

            Try something like this instead:

             

             

            variables["keys_email"] = "...";

            variables["keys_password"] = "...";

            variables["message_title"] = "...";

             

            Does that help at all?

             

            Ben Edwards

            >

            • 3. Re: how to pass parameters in http post as a form data
              SteveDepp

              Is this for AIR?

               

              You cannot add properties to URLVariable objects if you are not using AIR.

               

              What are you actually trying to do?

               

              You should probably be using HTTPService for sending POST variables.

              • 4. Re: how to pass parameters in http post as a form data
                BennyBeta Level 4

                If you are trying to do some advanced HTTP stuff you may want to try out: http://code.google.com/p/as3httpclientlib/

                • 5. Re: how to pass parameters in http post as a form data
                  genxsol Level 1

                  well, i just created an action script project in flex which runs swf in html.

                   

                   

                   

                  what i need:

                   

                   

                   

                  add 3 mandatory headers;

                   

                  URLRequestMethod.POST with 3 parameters as form data: keys[email]="abc"; keys[password]="abc"; message[title]="abc";

                   

                  my preference is to use multipart/form-data which can also include image/png

                   

                   

                   

                   

                   

                  problems:

                   

                   

                   

                  1- cant add user_agent in header, ArgumentError

                   

                  2- i need a simple multipart/form-data example to post my form data

                   

                   

                   

                   

                  Date: Fri, 5 Jun 2009 09:34:44 -0600

                  From: forums@adobe.com

                  To: mr.zeeshan@hotmail.com

                  Subject: how to pass parameters in http post as a form data

                   

                  Is this for AIR?

                   

                  You cannot add properties to URLVariable objects if you are not using AIR.

                   

                  What are you actually trying to do?

                   

                  You should probably be using HTTPService for sending POST variables.

                  >

                  • 6. Re: how to pass parameters in http post as a form data
                    SteveDepp Level 1

                    Firstly, you can't modify the user_agent header - that is a security violation.

                     

                    Secondly, to send POST data, try this...

                     

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  layout="vertical"
                        creationComplete="onCreationComplete()">
                        <mx:Script>
                            <![CDATA[
                                import mx.rpc.events.ResultEvent;
                                import mx.controls.Alert;
                               
                                private function onCreationComplete():void
                                {
                                    var params:Object = new Object();
                                    params.email = "emailAddress";
                                    params.password = "thePassword";
                                    params.title = "theTitle";
                                   
                                    myService.send(params);
                                }

                     

                                private function getDataHandler(event:ResultEvent):void
                                {
                                    Alert.show("Success");
                                }
                            ]]>
                        </mx:Script>
                        <mx:HTTPService id="myService" url="http://action.gcsc.att.com/v2/test.php"
                            useProxy="false" method="POST" resultFormat="text" result="getDataHandler(event)"
                            requestTimeout="30"/>
                    </mx:Application>

                     

                     

                    Thirdly, if you want to send files check out http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_7 .html

                    • 7. Re: how to pass parameters in http post as a form data
                      genxsol Level 1

                      thanks for the link, it seems very related but how can i import httpClient in as3?

                       

                       

                       

                      Date: Fri, 5 Jun 2009 09:43:04 -0600

                      From: forums@adobe.com

                      To: mr.zeeshan@hotmail.com

                      Subject: how to pass parameters in http post as a form data

                       

                      If you are trying to do some advanced HTTP stuff you may want to try out: http://code.google.com/p/as3httpclientlib/

                      >

                      • 8. Re: how to pass parameters in http post as a form data
                        genxsol Level 1

                        thanks for your reply!

                        my server only accept request with custom user_agent header.

                        i am doing it in java and it works perfectly. can i use httpclient in as3?

                         

                        Date: Fri, 5 Jun 2009 12:35:49 -0600

                        From: forums@adobe.com

                        To: mr.zeeshan@hotmail.com

                        Subject: how to pass parameters in http post as a form data

                         

                        Firstly, you can't modify the user_agent header - that is a security violation.

                         

                        Secondly, to send POST data, try this...

                         

                        <?xml version="1.0" encoding="utf-8"?>

                        <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  layout="vertical"

                            creationComplete="onCreationComplete()">

                            <mx:Script>

                                <![CDATA[

                                    import mx.rpc.events.ResultEvent;

                                    import mx.controls.Alert;

                                     

                                    private function onCreationComplete():void

                                    {

                                        var params:Object = new Object();

                                        params.email = "emailAddress";

                                        params.password = "thePassword";

                                        params.title = "theTitle";

                                         

                                        myService.send(params);

                                    }

                         

                                    private function getDataHandler(event:ResultEvent):void

                                    {

                                        Alert.show("Success");

                                    }

                                ]]>

                            </mx:Script>

                            <mx:HTTPService id="myService" url="http://action.gcsc.att.com/v2/test.php"

                                useProxy="false" method="POST" resultFormat="text" result="getDataHandler(event)"

                                requestTimeout="30"/>

                        </mx:Application>

                         

                         

                        Thirdly, if you want to send files check out http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_7 .html

                        >