views:

460

answers:

4

Hi,

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?

A: 

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.

Dennis Palmer
I just need some pointers, or even a link to a tutorial (I've searched around and had no luck) on the syntax for doing a POST to Asp.Net from flash in general...
Matt
+1  A: 

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

bleevo
Are you sure about that? I'm getting an IO Error and a Stream Error and people have told me it's most likely because the URL is incorrect. If I type in www.mysite.com/MyController/MyMethod into my address bar it says the resource cannot be found, but I know for a fact that the method exists because gets called in my javascript just fine (I've tested it).
Matt
+2  A: 

Check the URLRequest.data property and the URLRequest.method property in the docslink text

Basically the method property defines whether you are doing a HTTP GET or HTTP POST. 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.

Use that URLRequest instance in URLLoader and bobs your uncle. Also, if you are using flex you could also take a look at using the HTTPService component.

James Hay
A: 

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.

Alex Jillard