git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Authenticating using URLRequest Issue


Any particular reason you want to use URLRequest?
You can easily do it using HttpService.

var hs: HttpService
hs.url = "your API"
hs.method = "POST"
hs.contentType = "application/json"
hs.send(JSON.encode(loginObject))

-Deepak


On Wed 27 Jun, 2018 7:29 am Tucsonjhall, <Jhall@xxxxxxxxxxxxxx> wrote:

> When I test with Postman authenticating at an API site, I get a return
> token
> (which I need) fine. When I try in AS3, regardless of the permutation I
> try,
> it returns the html of the page one would see if they went to the post URL
> in a browser.
>
> One of the many permutations I've tried is:
>
> var loginJSON : String;
> loginObject = new Object();
> loginObject.username = "xxx@xxxxxxxxx";
> loginObject.password = "yyyyyyyyy";
> loginJSON = JSON.stringify( loginObject );
>
> var loader : URLLoader = new URLLoader();
> loader.addEventListener( "complete", onLoginComplete, false, 0, true );
> loader.addEventListener( "ioError", onIOError, false, 0, true );
>
> var request : URLRequest = new URLRequest();
> request.method = URLRequestMethod.POST;
> request.contentType = "application/json";
> request.url = "https://xxx.xxxxxxx.com/api/access-token/";;
> request.data = loginJSON;
>
> // Following taken out on this attempt
> // var header : URLRequestHeader = new URLRequestHeader( "Content-Type",
> "application/json" );
> // request.requestHeaders.push( header );
>
> try {
>         loader.load( request );
> } catch ( e : Error ) {
>         Alert.show( "There was a problem communicating with LeagueLobster.
> Error
> message: " + e.name + " Code: " + e.errorID + " " + e.message );
> }
>
> Does the server need to have a crossdomain.xml file or am I missing
> something else that's obvious to more experienced programmers?
>
> Thanks much
>
>
>
> --
> Sent from: http://apache-flex-users.2333346.n4.nabble.com/
>


( ! ) Warning: include(msgfooter.php): failed to open stream: No such file or directory in /var/www/git/apache-flex-development/msg02735.html on line 130
Call Stack
#TimeMemoryFunctionLocation
10.0006364568{main}( ).../msg02735.html:0

( ! ) Warning: include(): Failed opening 'msgfooter.php' for inclusion (include_path='.:/var/www/git') in /var/www/git/apache-flex-development/msg02735.html on line 130
Call Stack
#TimeMemoryFunctionLocation
10.0006364568{main}( ).../msg02735.html:0