2
votes

I've started to add HTTP support to a custom C# non-webserver application which seems to work fine from Firefox/IE/Chrome when typing in the URL directly to the browser - where I can see a returned text string in the page from my application.

The problem is when I try do the same from a HTTPRequest in JavaScript on a web page I don't get a response with Chrome or Firefox (It's fine in IE) - rather I get a status of zero from the HTTPRequest object. I can however see that my application from its debug output received the request from the browser and provided the response so the browser must not be like the response I send in this case with the exception of IE being less picky.

I've swapped between trying different POST and GET requests to no avail - eg:

request.open('GET', url, true); request.onreadystatechange = mycallback; //request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); request.send(null); //tried '' as well and other data with a POST

My simplest server reply I have tried is:

HTTP/1.1 200 OK\r\n Content-Length: 20\r\n Content-Type: text/plain\r\n \r\n ...........

I have tried 1.0 instead of 1.1, different headers such as Connection: Close, Accept-ranges and other random stuff as I tried to mimic other such responses I looked at with Wireshark.

Obviously it must be something simple but the magic combination eludes me!

Many thanks in advance.

1
A sudden thought I just had is the web page the JavaScript is on comes from a web server running on the same machine and thus with the same IP address as my custom server. However the Apache web server is running on port 80 but my custom server is on port 8080. Could it be that I am being bitten by the same origin security policy under Chrome and Firefox?iam

1 Answers

2
votes

And on that note I have answered my own question it was the cross domain security feature.

Which I have now fixed by adding the extra response header:

"Access-Control-Allow-Origin: *"

Hopefully that is useful for someone else in the future!