I'm trying to exchange data between a web page and a c# socket. The c# socket is running on the localhost. The webpage runs on a server and points to the localhost.
When the webpage sends a Get request to the c# socket an cross-domain error is shown.
XMLHttpRequest cannot load http://localhost:12345/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.1.3:9000' is therefore not allowed access.
This is the JS running on the web page (Angular).
var serviceUrl = 'http://localhost:12345';
var service = $resource(
serviceUrl,{}, {
getCard: {
method: "GET"
}
}
);
service.getCard();
This is a part of the code from the c# console application.
private static void Send(Socket handler, String data)
{
// Convert the string data to byte data using ASCII encoding.
byte[] byteData = Encoding.ASCII.GetBytes(data);
// Begin sending the data to the remote device.
handler.BeginSend( byteData
, 0
, byteData.Length
, 0
, new AsyncCallback(SendCallback)
, handler
);
How can i add header information to the response. The headers must be: Access-Control-Allow-Origin: * It doesnt work when i add it in front of the string.