$(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
0

HTTP 405 Error when defining ODataModel

Nov 21, 2016 at 09:29 AM

1.7k

avatar image
Former Member

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Nabi Zamani Nov 21, 2016 at 05:15 PM
3

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

Share
10 |10000 characters needed characters left characters exceeded
Jamie Cawley
Nov 21, 2016 at 05:00 PM
1

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Jamie Cawley ,

I'm facing the same issue here. I've raised a new post HTML5 App with SAP Web IDE on HCP using C4C Odata 2017.

I've followed the blog mentioned to create the connectivity. But it gets error 404 and I notice the path do have suffix "/webapp/...". I try open the link without webapp suffix and it's able to load the odata xml.

Any idea of these error?

Regards,

-Ben-

222.png (56.7 kB)
0
avatar image
Former Member Nov 21, 2016 at 10:18 AM
0

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

Show 1 Share
10 |10000 characters needed characters left 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

0
avatar image
Former Member Nov 21, 2016 at 02:20 PM
0

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


capture345.png (15.5 kB)
Share
10 |10000 characters needed characters left characters exceeded