3 Replies Latest reply on Mar 19, 2012 6:48 AM by Praful_Comp

    How to access web service with authentication in Flex 4.6

    Praful_Comp

      I want to call web service to authenticate username and password .

           I am using web service component of flex .

      I want to know how to pass the username and password along with web service compnent and get authenticated .

        • 1. Re: How to access web service with authentication in Flex 4.6
          drkstr_1 Level 4

          This should do the trick: http://stackoverflow.com/questions/490806/http-basic-authentication-with-httpservice-objec ts-in-adobe-flex-air

           

          See the last edit on the original post, where they modify the headers before sending the request.

          • 2. Re: How to access web service with authentication in Flex 4.6
            Praful_Comp Level 1

            Hi ,

                 I have tried it , but it's not working. Is there any other workaround?

             

                 I need to do Basic Authentication of web service which will ask the user credentials before accessing the web service when my code will try to hit the URL.

             

            I'm blocked at this. Can anybody help me plz???

             

             

            Thanks

            Praful

            • 3. Re: How to access web service with authentication in Flex 4.6
              Praful_Comp Level 1

              Hi ,

              Web service basic authentication is working fine .

              Now i need to call xyz function from  webservice which takes 2 parameter as email and password and will return object

               

              how to do that?

              please help .

               

              this is my code

               

               

              <fx:Script>
                <![CDATA[
                 import mx.rpc.events.FaultEvent;
                 import mx.rpc.events.ResultEvent;
                 import mx.rpc.soap.Operation;
                 import mx.rpc.soap.SOAPFault;
                 import mx.utils.Base64Encoder;
                 private var getdata:Operation;
                
                 private function authAndSend(service:HTTPService):void    
                 {     
                  var encoder:Base64Encoder = new Base64Encoder();            
                  encoder.insertNewLines = false;            
                  encoder.encode("username:password"); 
                  service.headers = {Authorization:"Basic " + encoder.toString()};
                  service.send();
                     
                 }
                

                
                 
                 private function resultHandler(event:ResultEvent):void        
                 {
                

               

                     var webresult:String=event.result.toString();
                 
                 }
                
                 private function resultFailed(event:FaultEvent):void
                 {
                  var err:String = event.fault.toString(); 
                 
                 }
                
                
                 
                ]]>
               
              </fx:Script>

               


              <fx:Declarations>
               
                <s:HTTPService id="service" url="web service url"
                      resultFormat="xml" result="resultHandler(event)">
                
                <s:request xmlns="">
                  <Email>{"parameter1"}</Email>
                  <Password>{"parameter2"}</Password>
                 </s:request>
                
                </s:HTTPService>
               
                </fx:Declarations>

               

              <s:Button id="button"

                  

                   label="call service"

                  

                   click="authAndSend(service)" />