rest - Sending preflight cors request in javascript -


i'm trying send post request custom api (which have credentials for) keep getting 401 error "unathorized". part of code makes request:

var httprequest = new xmlhttprequest(); var test = [{                           "action": "start",                           "time": "2014-05-02t13:09:22+02:00",                           "channel": {                           "id": "rtvslo1"                           },                           "content": {                             "id": "rtvslo1",                              "title": "testcontent",                              "channel_id": "rtvslo1",                              "time": "2014-05-02t13:09:22+02:00",                              "duration": 3                           },                           "subscriber": {                             "id": "f8721ca0-d1e9-11e3-9c1a-0800200c9a66",                             "country": "si"                           },                           "device": {                             "id": "012fa920-d1ea-11e3-9c1a-0800200c9a66",                             "type": "tv"                           },                           "hd": false,                           "test": true                         }];              var jsonstring = json.stringify(test);              httprequest.open('post', url, true);             httprequest.setrequestheader("authorization", "basic " + btoa(username + ":" + password));             httprequest.setrequestheader("content-type", "application/json");             httprequest.send(jsonstring); 

when im trying see error in chrome dev tools options request 401 unathorized, doesnt post.

in chrom dev tools output: name: events method:options status 401...

options http://xstreampipy.tvbeat.com/api/2.0/events 401 (unauthorized)myfunction @ test.html:39onclick @ test.html:60 test.html:1 xmlhttprequest cannot load http://xstreampipy.tvbeat.com/api/2.0/events. no 'access-control-allow-origin' header present on requested resource. origin 'null' therefore not allowed access. response had http status code 401.

any appreciated :)!

this error means rest request making cross domain i.e mydomain.com --> restservicedomain.com. these requests no longer valid or depricated(don't know why that). there many ways workaround problem. can use these links understand , implement solution -

i still trying implement cors request don't have running code.


Comments