$(function () { pageContext.i18n.modTalk = 'moderation talk'; pageContext.i18n.replyToComment = 'Reply'; pageContext.i18n.modTalkEmpty = 'moderation talk is empty'; pageContext.url.getModTalk = "/comments/%25ID%25/listModTalk.json"; pageContext.url.possibleCommentRecipients = "/comments/%ID%/possibleRecipients.json"; pageContext.url.commentEdit = '/comments/%25ID%25/edit.html'; pageContext.url.commentView = '/comments/%ID%/view.html'; pageContext.i18n.commentVisibility = { 'full': 'Viewable by all users', 'op': 'Viewable by the original poster', 'mod': 'Viewable by moderators', 'opAndMod': 'Viewable by moderators and the original poster', 'other': 'Advanced visibility', 'dialogTitle': 'Comment visibility', 'selectGroups': 'Visible to groups', 'selectOther': 'Other recipients', 'selectOriginalPoster': 'Original poster', 'selectModerators': 'Moderators', 'selectAssignees': 'Asked to answer users' }; pageContext.i18n.commentMenuLabels = { 'comment-edit': 'comments.menu.edit', 'comment-delete': 'comments.menu.delete', 'comment-convert': 'comments.menu.convert' };pageContext.i18n.answer= { bestAnswer: 'Best Answer', controlBar : { accept: 'Accept', unaccept: 'Unaccept', acceptCommand: 'Accept this answer as correct', cancelAcceptedCommand: 'Remove this answers accepted status' } }; window.croles = { u: false, op: false, m: false, og: false, as: false, ag: false, dc: false, doc: false, eo: false, ea: false }; tools.init({ q: { e: false, ew: false, eo: false, r: false, ro: false, d: false, dow: false, fv: false, c: false, co: false, p: false, tm: false , ms: false, mos: false }, n: { f: false, vf: false, vfo: false, vr: false, vro: false, c: false, co: false, vu: false, vd: false, w: false, wo: false, l: false }, c: { e: false, eo: false, d: false, dow: false, ta: false, tao: false, l: false }, a: { e: false, ew: false, eo: false, d: false, dow: false, a: false, aoq: false, ao: false, tc: false, tco: false, p: false, tm: false }, pc: croles }, { tc: true, nsc: true }); commandUtils.initializeLabels(); }); Skip to Content
avatar image
Former Member

HTTP 405 Error when defining ODataModel

Hello everyone,

I am trying to build a small SAPUI5 application, that uses an OData service. When trying to define the model like this:

var oModel = new sap.ui.model.odata.ODataModel("http://<server>:<port>/sap/opu/odata/sap/<service_name>");

I get the following error:

OPTIONS http://<server>:<port>/sap/opu/odata/sap/<service_name>/$metadata 405 (Method Not Allowed)

XMLHttpRequest cannot load http://<server>:<port>/sap/opu/odata/sap/<service_name>/$metadata. Response for preflight has invalid HTTP status code 405

Does someone have an idea about what to do in this case? I tried to search for an answer, but only found another guy with the same problem.

Thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Nov 21, 2016 at 05:15 PM

    The issue you are facing is related to the Same Origin Policy of browsers. CORS would be one solution to fix this, using a proxy (i.e. the HCP destinations mentioned by Jamie Cawley) would be another solution. For dev purposes you could also disable your browser's security features. The preflight OPTIONS request is sent by your browser automatically because of the Same Origin Policy. With this request your browser is basically trying to read the "CORS config" of the service you are trying to access. So the best thing for you would be to get familiar with the links I mentioned above...

    By the way: sap.ui.model.odata.ODataModel is deprecated and I suggest you to use sap.ui.model.odata.v2.ODataModel instead.

    Best, Nabi

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 21, 2016 at 05:00 PM

    You can not define a connection using an absolute path to a system different from where you are running your project from. You should be using a relative path with some form of proxy to call the backend. Web IDE handles this for you using HCP destinations, if using eclipse you can use the simple proxy servlet, otherwise you may be able to disable the browser security settings.

    Regards,

    Jamie

    SAP - Technology RIG

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 21, 2016 at 10:18 AM

    Hi Johannes Roth ,

    Actually this error comes when you'r service doesn't support the method like POST , GET, PUT ,DELETE whichever you are calling. I think your get to metadata is not implemented . Please first test your service on browser or any tool like POSTMAN .

    thanks

    Viplove

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello Viplove,

      Thank you for your answer.

      All methods work perfectly fine when trying them in a browser or in the SAP Gateway Client. Only when I try using the service to define an ODataModel it will show the error mentioned above.

      Could it be, that the error is caused by the method "OPTIONS" that seems to be used by the ODataModel?

      High regards,

      Johannes Roth

  • Nov 21, 2016 at 02:20 PM

    Hi Johannes Roth,

    As i understood u are unable to call the services using odatamodel right?

    If yes please go through the image below.

    capture345.png

    Hope you will get the solution.

    Regards,

    Deepak Raj

    Add comment
    10|10000 characters needed characters exceeded