Reputation: 15494
I want to open a web page on the same tab when the user clicks a movieclip. I'm using this method:
var url:String = "http://www.google.com";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request);
} catch (e:Error) {
trace("Error occurred!");
}
But I have no idea of how to open it sending POST vars. Is that possible?
Upvotes: 2
Views: 5885
Reputation: 1
If running in Flash Player and the referenced form has no body, Flash Player automatically uses a GET operation, even if the method is set to URLRequestMethod.POST. For this reason, it is recommended to always include a "dummy" body to ensure that the correct method is used.
Upvotes: 0
Reputation: 772
Regarding to "sub-question" above:
for some reason the vars were send using GET instead of POST, any idea?
That post AS3 POST Request sending as a GET may help if you are stumble upon this post like me. Basic idea is: don't let the request.data goes empty/null. Just add something "dummy" or "unobtrusive" (from the server's point of view) like request.data = "\r\n"; this should prevent flash runtime overwrite your "POST" request with a "GET". It worked for me (thanks to my serverside app. was enough robust to handle nicely of which querystrings that starts with an empty parameter has an empty key and an empty value).
Upvotes: 1
Reputation: 6127
Yes, it is possible, by specifying POST as the method on URLRequest, and using flash.net.URLVariables for the vars. This is the example from the documentation:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html
package {
import flash.display.Sprite;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
public class URLRequest_method extends Sprite {
public function URLRequest_method() {
var url:String = "http://www.[yourDomain].com/application.jsp";
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
variables.exampleSessionId = new Date().getTime();
variables.exampleUserLabel = "guest";
request.data = variables;
request.method = URLRequestMethod.POST;
navigateToURL(request);
}
}
}
Upvotes: 10