You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Tucsonjhall <Jh...@cactusware.com> on 2018/06/27 01:59:08 UTC

Authenticating using URLRequest Issue

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@xxxxx.com";
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/

Re: Authenticating using URLRequest Issue

Posted by Deepak MS <me...@gmail.com>.
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, <Jh...@cactusware.com> 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@xxxxx.com";
> 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/
>

Re: Authenticating using URLRequest Issue

Posted by Tucsonjhall <Jh...@cactusware.com>.
Thanks. I'll work on both today and see what happens. 



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/