Error Faced

May 10, 2012 at 8:47 AM
Edited May 10, 2012 at 9:22 AM

Hello there,

I have been doing a project on python using django and trying to consume the odata with datajs however I have faced with like error 501 Not Implemented with the header request method as OPTIONS. At first I thought it was the python web framework that has secured website causing it to be unable to retrieve. So I made a change to php and tried it again and now the error faced is also 501 and 401 Access Denied.

I don't know is it because of my codes were wrong or any other things.

Would anyone give me a start off like

OData.read({ requestUri: "http://something.svc/Hi", user: "hello", password: "hey" }, function(data) {

do something ...

});

How do I put the request header, or even the authentication details. Thanks for the help in advance.

 

Edit: This is my code for reference,

function getServiceData() {
   var request = {
          requestUri: "http://api.myservice.org/something.svc/MyDataSet?$filter=Name eq 'Hey',
          method: "GET",
          user: "00000000000000000000000001",
          password: "GSRGrgaseg34t34r512341$#/"
};

OData.read(request, function(data, response) {
           var html += "";
           for (var i = 0; i < data.results.length; i++) {
              html += "<div>" + data.results[i].Name + "</div>";
           }
           document.getElementById("myOptionsId").innerHTML = html;
});
 

May 11, 2012 at 9:52 PM

Hi Jay3x,

   You can control the header of the request by setting the headers object in the request.  For example, if I want to add a header of my own:

function getServiceData() {
   var request = {
          requestUri: "http://api.myservice.org/something.svc/MyDataSet?$filter=Name eq 'Hey',
          headers: {
               "My-Header": "value",
                OtherHeader: "other value" 
          },
          method: "GET",
          user: "00000000000000000000000001",
          password: "GSRGrgaseg34t34r512341$#/"
};

OData.read(request, function(data, response) {
           var html += "";
           for (var i = 0; i < data.results.length; i++) {
              html += "<div>" + data.results[i].Name + "</div>";
           }
           document.getElementById("myOptionsId").innerHTML = html;
});

As for the user name and password in the request, they are going to be passed eventually to the XHR.Open method. 



Now about the 501.  That is completely server side, could you please let me know a couple of more details about it??  The OData enpoint you are trying lives in the same domain that you web app??  Which browser are you using?  I would think that you are trying to do a cross domain request and the browser is being smart and trying to do a CORS (level2 XHR) request to it.. that's why yo see the OPTIONS request being sent.. but seems that the endpoint doesn't know what to do with the OPTIONS request and replies with the 501.

Regards,

Alex Trigo.