adlnet / xAPIWrapper

Wrapper to simplify communication to an LRS
https://adlnet.gov/projects/xapi/
Apache License 2.0
219 stars 114 forks source link

ERR_CONNECTION_REFUSED #148

Closed LiangZhang2017 closed 5 years ago

LiangZhang2017 commented 5 years ago

Here I mee one bug. It is "OPTIONS .... net::ERR_CONNECTION_REFUSED". It is from at Object.ADL.XHR_request (http://localhost:8080/xAPI/xapiwrapper.js:1604:13), which is command line is "xhr.send(ieXDomain ? ieModeRequest.data : data);" The error hint shows like:

Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://localhost:8000/xapi/statements?enpoint=http%3A%2F%2Flrs.x-in-y.com%2Fdata%2FxAPI%2F&auth=Basic%20...................................'.

Now I am not sure where is the error from and I have check the endpoint and auth information, when I run them in Post Man, it works good. But here it doesn't work now. So now I am not clear where does the problem come from. Thanks.

oliverfoster commented 5 years ago

You've just published your login information and your endpoint url to the world.

auth=Basic%20[This is a base64 encoded username and password, you should probably edit your message to delete it]

You have 3 servers you're attempting to use localhost:8080, localhost:8000 and http://lrs.x-in-y.com. If localhost:8080 is the web server you're using to host your development files, and lrs.x-in-y.com is your lrs, what is localhost:8000?

vbhayden commented 5 years ago

Is the wrapper itself producing that URL or is this maybe just some confusion with how to retrieve statements from an LRS?

Auth credentials and the endpoint should be specified by the wrapper's configuration, not as query parameters. The simplest way to retrieve statements from an LRS (here we use the public ADL LRS) would be:

  ADL.XAPIWrapper.changeConfig({
    "endpoint" : "https://lrs.adlnet.gov/xapi/",
    "auth" : "Basic " + btoa("tom:1234"),
  })

  // edit for parsing
  ADL.XAPIWrapper.getStatements(null, null, function(xhr) {
    if (xhr.status == 200) {
      let payload = JSON.parse(xhr.responseText)
      console.log(payload.statements)
    }
  });

You can also specify search parameters for that first argument, but all of this is covered on the repo's front page ReadMe.

LiangZhang2017 commented 5 years ago

You've just published your login information and your endpoint url to the world.

auth=Basic%20[This is a base64 encoded username and password, you should probably edit your message to delete it]

You have 3 servers you're attempting to use localhost:8080, localhost:8000 and http://lrs.x-in-y.com. If localhost:8080 is the web server you're using to host your development files, and lrs.x-in-y.com is your lrs, what is localhost:8000?

Yes, I should the switch the request url, usename and password in xapiwrapper.js. Appreciate!

LiangZhang2017 commented 5 years ago

Is the wrapper itself producing that URL or is this maybe just some confusion with how to retrieve statements from an LRS?

Auth credentials and the endpoint should be specified by the wrapper's configuration, not as query parameters. The simplest way to retrieve statements from an LRS (here we use the public ADL LRS) would be:

  ADL.XAPIWrapper.changeConfig({
    "endpoint" : "https://lrs.adlnet.gov/xapi/",
    "auth" : "Basic " + btoa("tom:1234"),
  })

  // edit for parsing
  ADL.XAPIWrapper.getStatements(null, null, function(xhr) {
    if (xhr.status == 200) {
      let payload = JSON.parse(xhr.responseText)
      console.log(payload.statements)
    }
  });

You can also specify search parameters for that first argument, but all of this is covered on the repo's front page ReadMe.

Sure, I commit a error that I should change the auth information in xapiwrapper.js. Your example query is great. Thanks a lot.

vbhayden commented 5 years ago

Np, glad to help!

LiangZhang2017 commented 5 years ago

Is the wrapper itself producing that URL or is this maybe just some confusion with how to retrieve statements from an LRS? Auth credentials and the endpoint should be specified by the wrapper's configuration, not as query parameters. The simplest way to retrieve statements from an LRS (here we use the public ADL LRS) would be:

  ADL.XAPIWrapper.changeConfig({
    "endpoint" : "https://lrs.adlnet.gov/xapi/",
    "auth" : "Basic " + btoa("tom:1234"),
  })

  // edit for parsing
  ADL.XAPIWrapper.getStatements(null, null, function(xhr) {
    if (xhr.status == 200) {
      let payload = JSON.parse(xhr.responseText)
      console.log(payload.statements)
    }
  });

You can also specify search parameters for that first argument, but all of this is covered on the repo's front page ReadMe.

Sure, I commit a error that I should change the auth information in xapiwrapper.js. Your example query is great. Thanks a lot.