What is the proper way to do an http Post from Flash to an Asp.Net MVC Application?


What is the proper way to do an http Post from Flash to an Asp.Net MVC Application?



Here are a few of the things I need to know:

  1. What do you put for the URLRequest? It's confusing me a bit since Asp.Net MVC is methods and not pages

  2. How do you assign parameters for the POST?

  3. How to you execute the URLRequest to complete the Http Post?

Any information on how to do a Post from Flash to an Asp.Net MVC Application would be helpful.

Thanks,
Matt

Edit: I'm asking this because I'm getting an IO Error and a Stream Error:

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: http://www.mysite.com/MyController/MyMethod at Main/postToMySite()

And people have told me that this usually means the url does not exist. I've tried typing: http://www.mysite.com/MyController/MyMethod into the address bar and it says the resource cannot be found, but I know for a fact that it does exist because it gets called perfectly fine from my javascript (I've tested it).

    [AcceptVerbs(HttpVerbs.Post)]     public ActionResult MyMethod(FormCollection formValues)     {         return this.Json("Completed");     } 

NOTE!!!! I Just tested it on a different url, one that didn't have the [AcceptVerbs(HttpVerbs.Post)] and it didn't give me any errors! Any idea of why this is? Will doing a post to a method without the [AcceptVerbs(HttpVerbs.Post)] still work?




Spinning javascript menu

1:



make link on SWF File to another HTML
Check the URLRequest.data property and the URLRequest.method property in the docslink text.
Flex and AIR passing data between each other
Basically the method property defines whether you are doing a HTTP GET or HTTP POST.


How do you find the URL to the SWF file using ActionScript 2?
The object you put into the data property is the data that will be added as a query string in an HTTP GET or added as the message body for a HTTP POST..
Trouble with LoadVars.sendAndLoad in Actionscript 2 across different computers
Use that URLRequest instance in URLLoader and bobs your uncle.


Play video from local file using Adobe AIR
Also, if you are using flex you could also take a look at using the HTTPService component..
Providing alternative images if Adobe Flash isn't available


Flex: Determine if a component is showing

2:


You do not need to do anything special for ASP.NET MVC..


3:


How would you do a POST to a regular asp.net page from flash? It shouldn't be any different.. Edit: If you use [AcceptVerbs(HttpVerbs.Post)], on a method, then you won't be able to access that method by typing the url into your browser.

I would think that most of the time, you'd also have a GET method overload for that same Action name like so:.
// // GET: /MyController/MyMethod  public ActionResult MyMethod() {     return View(); }  // // POST: /MyController/MyMethod  [AcceptVerbs(HttpVerbs.Post)] public ActionResult MyMethod(FormCollection formValues) {     return this.Json("Completed"); } 
If you don't have the overloaded method that responds to GET, then http://www.mysite.com/MyController/MyMethod will not work as a GET, which is what happens when you type the url in your browser's address bar.. Yes, doing a POST on a method without [AcceptVerbs(HttpVerbs.Post)] will still work, but the attribute is there to prevent hitting the method with other verbs, since in general the methods that are responding to POST actions should ONLY respond to POST actions..


4:


You might have some luck trying using the NetConnection class in Flash to make the POST to your server.

You'll probably need to setup some sort of .NET AMF stuff to get it working, but once you have that setup, it's very easy to pass data back and forth..



66 out of 100 based on 31 user ratings 206 reviews