Clearing StageWebView cache on Air Simulator - actionscript-3

I use StageWebView for Facebook authentication in my mobile game. Everything works fine except that I can never reset StageWebView cache. I remain logged into Facebook and because of that I can't test authentication with another Facebook account.
I checked "Clear data on application launch" on debug settings to no avail.
Any ideas?

// use the token received for the logout:
// accessToken = getAccessTokenEvent.accessToken;
stageWebView = new StageWebView();
stageWebView.addEventListener(Event.COMPLETE,completa);
stageWebView.stage = FlexGlobals.topLevelApplication.stage;
stageWebView.viewPort= new Rectangle(0,0,FlexGlobals.topLevelApplication.stage.width-10,FlexGlobals.topLevelApplication.stage.height-10);
stageWebView.loadURL("https://m.facebook.com/logout.php?next=http://m.facebook.com&access_token="+ accessToken +"&confirm=1");
var loginRequest:URLRequest = new URLRequest();
loginRequest.method = URLRequestMethod.GET;

Related

sending a GET request from a banner

I have to build a banner where people fill a form with their name and email send when they click, we send the data in order to send them back a brochure instantly.
I am not a dev, so it is a little bit confusing for me and I hope my explanations will be clear enough.
Apparently, the website only accept POST request but we cannot send like that from the banner due to crossdomain issue. So the request has to be send as a GET.
We found this website which does the conversion:
http://get-to-post.nickj.org/
for the purpose of the test, everything is hardcoded. When we test, this url:
http://get-to-post.nickj.org/?http://www.vikingrivercruises.co.uk/Forms/SaveRequestBrochures?InquiryReason[0]=2351&InquiryMessage[0]=UK+River+Brochure+Download&InquiryType[0]=Brochure-d&InquiryReason[1]=1450&InquiryMessage[1]=UK+Brochure+Requests+%28from+web%29&InquiryType[1]=Brochure&BrochureCode=UKBR15&SelectedBrochuresDeliverability=UKBR15+mail-yes+ebrochure-yes&selectedBrochures=UKBR15&Title=Mr.&FirstName=Andrew&LastName=Davies&EmailAddress=nicom21a%40gmail.com&PhoneNumberString=098921313132312&Country=United+Kingdom&OtherCountry=&Address1=&Address2=&Address3=&City=&State=&OtherState=&Zip=&EmailMeSpecialOffers=true&FriendTitle=&FriendFirstName=&FriendLastName=&FriendEmailAddress=&RedirectUrl=http%3A%2F%2Fwww.vikingrivercruises.co.uk%2Fbrochures%2Frivers-brochure-thank-you.html
and copy past it in the browser, it works perfectly and we receive a brochure instantly, but when I try to replicate it from the banner it doesn't work.
Here is my code, many thanks
var requestVars:URLVariables = new URLVariables();
requestVars.link = 'InquiryReason[0]=2351&InquiryMessage[0]=UK+River+Brochure+Download&InquiryType[0]=Brochure-d&InquiryReason[1]=1450&InquiryMessage[1]=UK+Brochure+Requests+%28from+web%29&InquiryType[1]=Brochure&BrochureCode=UKBR15&SelectedBrochuresDeliverability=UKBR15+mail-yes+ebrochure-yes&selectedBrochures=UKBR15&Title=Mr.&FirstName=Andrew&LastName=Davies&EmailAddress=nicom21a%40gmail.com&PhoneNumberString=098921313132312&Country=United+Kingdom&OtherCountry=&Address1=&Address2=&Address3=&City=&State=&OtherState=&Zip=&EmailMeSpecialOffers=true&FriendTitle=&FriendFirstName=&FriendLastName=&FriendEmailAddress=&RedirectUrl=http%3A%2F%2Fwww.vikingrivercruises.co.uk%2Fbrochures%2Frivers-brochure-thank-you.html'
var request:URLRequest = new URLRequest();
request.url = 'http://get-to-post.nickj.org/?http://www.vikingrivercruises.co.uk/Forms/SaveRequestBrochures';
request.method = URLRequestMethod.GET;
request.data = requestVars;
for (var prop:String in requestVars) {
trace("Sent " + prop + " as: " + requestVars[prop]);
}
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
I also tried like that
request.url = 'http://get-to-post.nickj.org/?http://www.vikingrivercruises.co.uk/Forms/SaveRequestBrochures?';
I think there are many points in your case that should be clarified :
If you want send a URL request to a server, but ignores any response, and I think this is your case because you can't get response, It's better to use sendToURL instead of URLLoader.load().
If you test your swf on line, you will get a security error because the used site(http://get-to-post.nickj.org/) doesn't have a crossdomain.xml file to get authorization to execute the URL : http://get-to-post.nickj.org/?http://www.example.com/?param=value.
Even when you execute your sendToURL successfully, you have another problem because the site that you have mentioned, which convert GET request to a POST one, will not do the job because it's creating a page with a POST form with your data and submitting it when the page is loaded which is never fired with flash.
So, I think it's better to see the crossdomain problem with your target site (vikingrivercruises) to give you authorization to send POST data. And if It's always impossible, try to set another URL (site) that get your GET data and send it via curl, for example, to your destination.

search embeded webpage source in vb.net

I wrote a program that includes an embedded web browser that loads a website which have a changing part (the part changes about 2 times a week and it have no regular timing pattern) that I want to search for a particular part in the opened webpage source code after refreshing the webpage in a specified time interval.
I found many things similar to my question but this is what I want and those questions doesn't have:
search embedded webpage source (they searching the webpage without embedding, and I had to embed it because I had to login before I see the particular page)
so this is the procedure I'm trying to do:
1- open a website in embedded web browser
2- after user logged in, with a press of button in program, it hides the embedded
web browser and start to refresh the page in a time interval (like
every minute) and search if the particular code changed in the source of
that opened webpage
any other/better Ideas appreciated
thanks
Many years ago I wrote an app to reintegrate forum posts from several pages into one and I struggled with the login issue too and thought it was only possible using an embedded browser. As it turns out, it's possible to use System.Net in .NET to handle web pages that need a login as you can pull the cookies out and keep them on hand. I would suggest you do that and move away from the embedded browser.
Unfortunately I wrote the code in C# originally, but as it's .NET and is mostly classes-based, it shouldn't be too difficult to port over.
The Basic Principle
Find out what information is included in the POST when you login, which you can do in Chrome with developer mode on (F12). Convert that to a byteArray, POST it to the page, store the cookies and make another call with the cookie data later on. You will need a class variable to hold the cookies.
Code:
private void Login()
{
byte[] byteArray = Encoding.UTF8.GetBytes("username=" + username + "&password=" + password + "&autologin=on&login=Log+in"); // Found by investigation
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("yourURL");
request.AllowAutoRedirect = false;
request.CookieContainer = new CookieContainer();
request.Method = "POST";
request.ContentLength = byteArray.Length;
request.ContentType = "application/x-www-form-urlencoded";
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
if (((HttpWebResponse)response).StatusCode == HttpStatusCode.Found)
{
// Well done, your login has been accepted
loginDone = true;
cookies = request.CookieContainer;
}
else
{
// If at first you don't succeed...
}
response.Close();
}
private string GetResponseHTML(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = false;
// Add cookies from Login()
request.CookieContainer = cookies;
request.ContentType = "application/x-www-form-urlencoded";
WebResponse response = request.GetResponse();
string sResponse = "";
StreamReader reader = null;
if (((HttpWebResponse)response).StatusCode == HttpStatusCode.OK)
{
reader = new StreamReader(response.GetResponseStream());
sResponse = reader.ReadToEnd();
reader.Close();
}
response.Close();
return sResponse;
}
Hope that helps.
I had to change to C# and I found what I was looking for:
string webPageSource = webBrowser1.DocumentText;
That gave me the source of web page opened in webBrowser1 control.

API Request with adobe AIR

I am trying to consume delicious api in adobe AIR AS3 project described here: https://github.com/avos/delicious-api
particularly the suggest api (/v1/posts/suggest) described at the end of this page: https://github.com/avos/delicious-api/blob/master/api/posts.md
In debug mode the app asks for username and password and keeps asking it even after providing valid username and password and never tracing the response. I have no idea what's going wrong here. Below is my code:
var request:URLRequest = new URLRequest("https://api.del.icio.us/v1/posts/suggest?red=api&url=http%3A%2F%2Fyahoo.com");
request.method = URLRequestMethod.POST;
//encoded string using as3 class at https://github.com/MoritzStefaner/revisit/blob/master/lib/com/hurlant/util/Base64.as
var encoded:String = Base64.encode("validusername:validpassword");
trace(encoded);
var credsHeader:URLRequestHeader = new URLRequestHeader("Authorization", "Basic " + encoded);
request.requestHeaders.push(credsHeader);
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, handleResults);
loader.load(request);
function handleResults(evt:Event):void
{
var response:String = evt.target.data as String;
trace("response:" + response);
}
From taking a brief look at the linked API, none of the methods suggest support for authentication information being sent as part of the POST body (which is what your code is doing). So unless that is documented somewhere else, you are using the API incorrectly. It's also reasonably rare to see an HTTP POST combined with a QueryString (which is again what your code above is doing) so that is a little odd.
I think Delicious just needs HTTP Basic auth, which is covered in an SO question here.

As3 - LocalConnection between SWF and AIR desktop app

I need to send a text from an embedded SWF (Web browser) to an AIR based desktop app.
I did everything like explained in the documentation but I can't establish a connection.
Does anybody see what I did wrong or can point me to a working example?
From the SWF:
function startConnection(e:Event=null):void
{
var localConnection:LocalConnection
localConnection = new LocalConnection();
localConnection.client = this;
localConnection.allowDomain("app#com.example.desktop");
var textToSend = "Hello world! Source: http://www.foobar.com";
localConnection.send("app#com.example.desktop:connectionName", "methodName",textToSend);
}
From the AIR desktop app:
function onBrowserInvoke (event:BrowserInvokeEvent):void{
var localConnection:LocalConnection
localConnection = new LocalConnection();
localConnection.client = this
localConnection.allowDomain("example.com");
localConnection.connect("connectionName");
}
Thank you.
Uli
The working code is:
AIR:
var localConnection:LocalConnection = new LocalConnection();
localConnection.send("_myConnection", "methodName", "Hello world! Source: http://www.foobar.com");
SWF:
var localConnection:LocalConnection = new LocalConnection();
localConnection.allowDomain("app#airtest"); //or use "*" wildcard to allow any domains and AIR applications
localConnection.client = this;
localConnection.connect("_myConne‌​ction");
Where airtest is the app id for AIR application. Use the _ symbol before local connection name for supporting unpredictable domain names (it'll work in debug mode and via http).

Flex: Export Excel via Servlet

I want a user to press an excel button and get prompted to download an excel file. I normally do it like this:
var dest:String = excelEndpoint;
var request:URLRequest = new URLRequest();
request.url = dest;
fr.download( request,'Locates.xls' );
fr.addEventListener(HTTPStatusEvent.HTTP_STATUS, handleStatus);
fr.addEventListener(IOErrorEvent.IO_ERROR, handleErr);
However, now I need to pass an object to the servlet. Seeing that you can't do that with URLRequest I tried using HTTPService:
var service:HTTPService = new HTTPService();
service.url = excelEndpoint;
service.method = "POST";
service.showBusyCursor = true;
service.addEventListener("result", httpResult);
service.addEventListener("fault", httpFault);
service.send( myObject);
Now I can get my data (myObject) to the servlet successfully, but I don't get prompted for a download.
How can I do that? Is it even possible with HTTPService?
Thanks for any helpful tips.
I don't think there is anything you can do w/ a remote request from the Flash Player to prompt the user to download something. The way I have done this in the past is two fold:
Remote request pings server that generates the excel file and saves it to a temporary directory. The request returns a URL to the Flex app as the result of the call.
When Flex app gets the result--a URL--it creates a URL request and pops it open in a new window, prompting the user to download the generated excel sheet.
I don't see a way to do this in one shot; because the return value from the Flex HTTPService call goes to the Flash Player, not the browser.
SOLVED:
I wanted to accomplish this with 1 remote call and the way I found to do this while passing an object that contained collections is this:
var uv:URLVariables = new URLVariables();
uv.typesColl = myObj.types.toString();
uv.partiesColl = myObj.parties.toString();
uv.statuses = myObj.statuses.toString();
Basically, create a property on the URLVariables object for each collection and then set all collections toString();
Hope that helps someone.