0

Just trying to figure out the proper syntax for making a POST to an HTTP Servlet from Flex. A Java developer gave me this URL to call:

http://myUrl:myPort/myProject/test/getFile/?fileId=1225

I want to build the the HTTPService url dynamically, meaning I pass the '1225' at the end.

My question is regarding how to translate that to MXML. Does that mean my HTTPService object looks like this?

<mx:HTTPService
    id="rawFileServlet"
    url="http://myUrl:myPort/myProject/test/getFile/?fileId="
    method="POST"
    showBusyCursor="true">

    <mx:request xmlns="">
        <fileId>

        </fileId>
    </mx:request>

</mx:HTTPService>

And my call is this:

params["fileId"] = 1225; httpServ.send(params);

Is that right? Something seems strange about it.

Here's updated code that works but doesn't allow me to trap remote errors nicely:

var url:String = model.fileUploadServletUrl;

        var request:URLRequest = new URLRequest();
        request.method = 'POST';
        request.url = url;

        var uvar:URLVariables = new URLVariables();
        uvar.fileId = evt.fileId;

        request.data = uvar;

        try{
            navigateToURL( request );
        }
        catch( e:Error ){
            ErrorManager.processRemoteError( 'Download Excel failed' );
        }

1 Answer 1

3

If you form your parameters in ActionScript in send() method use the following:

<mx:HTTPService
    id="rawFileServlet"
    url="http://myUrl:myPort/myProject/test/getFile/"
    method="POST"
    showBusyCursor="true" />

And you can use simple object for params:

var params:Object = {fileId: 1225};
rawFileServlet.send(params);
Sign up to request clarification or add additional context in comments.

7 Comments

This is the correct way. It should also be mentioned that if the URL is different than where your swf is located, you'll need a crossdomain policy file on the web server.
thank you, it worked like a charm. One addendum, this URL should prompt me to download a file. It works if I copy and paste link in browser, but launching it locally from IDE, all I get is result msg back from HTTP service call. Is there a network setting I need to change or s/thing?
I'm not sure about that. I'm calling a script on a Java Servlet, not pointing to a specific file to download.
If result is a file it doesn't matter. Try to use URLLoader. It accepts URLVariables as data of URLRequest.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.