Код: Выделить всё
listener = new HttpListener();
listener.Prefixes.Add("http://localhost:8083/");
listener.Prefixes.Add("http://127.0.0.1:8083/");
listener.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
< /code>
И вот мой пост Ajax < /p>
.ajax({
type: "POST",
url: 'http://localhost:8008/',
data: test_data,
crossDomain: true,
dataType: 'json',
success: function(data) {
//Use data
}
});
Эта настройка должна работать, только проблема, когда я сейчас нажимаю кнопку, я получаю ошибку xmlhttprequest не может загрузить http: // localhost: 8083/. В запрашиваемом ресурсе нет заголовка «Контроль доступа. Происхождение 'http: // localhost: 8081', следовательно, не допускается доступа. В ответе был HTTP Code Code 503. List imgraw = File.ReadAllBytes(@"C:\Users\USER\Pictures\image.jpg").ToList();
string base64ImageRepresentation = Convert.ToBase64String(imgraw.ToArray());
byte[] imgDataArray = Encoding.ASCII.GetBytes("data:image/jpg;base64," + base64ImageRepresentation);
byte[] responseConfigArray = Encoding.ASCII.GetBytes("HTTP/1.1\r\nCache-Control: no-cache\r\nAccess-Control-Allow-Origin: *\r\n\r\n");
byte[] buffer = new byte[responseConfigArray.Length + imgDataArray.Length];
responseConfigArray.CopyTo(buffer, 0);
imgDataArray.CopyTo(buffer, responseConfigArray.Length);
var response = context.Response;
response.ContentLength64 = buffer.Length;
response.StatusCode = 200;
response.StatusDescription = "OK";
response.OutputStream.Write(buffer, 0, buffer.Length);
...
Подробнее здесь: https://stackoverflow.com/questions/363 ... p-listener
Мобильная версия