Web ページと ac# ソケットの間でデータを交換しようとしています。c# ソケットはローカルホストで実行されています。Web ページはサーバー上で実行され、localhost を指します。
Web ページが Get 要求を C# ソケットに送信すると、クロスドメイン エラーが表示されます。
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.
これは Web ページ (Angular) で実行されている JS です。
var serviceUrl = 'http://localhost:12345';
var service = $resource(
serviceUrl,{}, {
getCard: {
method: "GET"
}
}
);
service.getCard();
これは、C# コンソール アプリケーションのコードの一部です。
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
);
応答にヘッダー情報を追加するにはどうすればよいですか。Access-Control-Allow-Origin: * 文字列の前に追加すると機能しません。