cancel
Showing results for 
Search instead for 
Did you mean: 

HTTP 405 Error when defining ODataModel

11-21-2016 10:29 AM
5931 views 6 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

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.

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

NabiZamani
Contributor

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

Answers (3)

Answers (3)

jamie_cawley
Product and Topic Expert
Product and Topic Expert

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

benlim
Contributor
0 Likes

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-

former_member203031
Contributor
0 Likes

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

Former Member
0 Likes

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

Former Member
0 Likes

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