Page 1 of 1

CORS Origin null from STA SDK 3.0 ?

PostPosted: Fri Aug 01, 2014 3:09 am
by rob.1_1
When I try to use the following code from the sdk 3.0 emulator I get a 405 - Method Not Allowed, because XmlHttpRequest cannot load my URL - Origin Null not allowed by Access-Control-Allow-Origin ... CORS is working with identical code on other platforms , is it perhaps because the browser in the emulator treats application script domain as file:// (and sets to null) rather than localhost:// ?

I feel I must be missing something, or everyone would have the same issue ?

--------------------
function postToURL(url, process,data){

if (XHRObj !== null) {
XHRObj.destroy();

}
XHRObj = new XMLHttpRequest();

if (XHRObj)
{
console.log(\"setting up POST\");


if (XHRObj.overrideMimeType)
{
XHRObj.overrideMimeType('text/plain');
}

XHRObj.withCredentials = true;

XHRObj.open(\"POST\", url, true);

Process = process;

XHRObj.onreadystatechange = readyStateChanged;

console.log(\"object opened - \" + url);

var auth = window.btoa(LoggedInUser + \":\" + LoggedInPassword);

console.log(\"credentials encoded\");
console.log(\"Auth header is \" + auth);

XHRObj.setRequestHeader(\"Authorization\", \"Basic \" + auth);
// XHRObj.setRequestHeader(\"Access-Control-Allow-Origin\",'*');
XHRObj.setRequestHeader(\"Content-Type\", \"application/json; charset=utf-8\");

console.log(\"request header set\");

XHRObj.send(data);
}


console.log(\"XHR request processed , readyState is \" + XHRObj.readyState);
}
--------------------

CORS Origin null from STA SDK 3.0 ?

PostPosted: Sun Aug 03, 2014 6:41 pm
by Support_STA
Hi,

Did you try to load a html file from your source? (In case,we have not tried before, but we think load() function of Jquery would be better).
Besides, hope this documentwill be helpful for you.

Regards,
STA Support

CORS Origin null from STA SDK 3.0 ?

PostPosted: Mon Aug 04, 2014 2:10 am
by rob.1_1
If you look at the code I posted (which is from index.html of the app) you'll see I am posting an xmlhttprequest to a url and expecting a JSON response ... the server has CORS support and should be returning the correct response headers ...

CORS Origin null from STA SDK 3.0 ?

PostPosted: Mon Aug 04, 2014 7:21 pm
by Support_STA
Hi,

As you mentioned, emulator treats application as file:// not localhost://.
So doing ajax from file URL isinconsistently, e.g: Chromeentirely disallows them.
For solution, you can upload your source to a server or using your staging server to check it with emulator.

Regards,
STA Support

CORS Origin null from STA SDK 3.0 ?

PostPosted: Tue Aug 05, 2014 9:32 am
by rob.1_1
It's disappointing, when you consider the LG webOS TV emulator and the Samsung SMART TV emulator, both based on VirtualBox images can do it ... is there no way to turn off checking by the browser JUST in the emulator image (Chrome can do -ignore-security-settings) ?