Skip to Content
0

Preflight request doesnt pass access control check when sending POST to IoTMMS via WS

Oct 27, 2016 at 08:35 PM

321

avatar image

I have created an HTML5 app that i am running in HCP which shows sensor data coming off my Raspberry PI which works fine. However i would like to enable bi-directional communication and also be able to send messages to it via the Websockets Push functionality. I have defined my ajax request with the following parameters:

type: 'POST'

headers: "Authorization" : "Bearer b6d385552c9c49090ad65c48e896dc4"

url:https://iotmmsd2b412a60.us2.hana.ondemand.com/com.sap.iotservices.mms/v1/api/http/push/af55c60f-13fc-47b0-b09d-00f318da5d1d

data: ("method":"ws", "sender":"Sensor Monitor Application", "messageType":"243dbaf4dcb840dfafbe", "messages":[ { "photo_request": "false", "led_display": "test test"]}

Where the photo_request boolean is for the pi camera to capture an image and the led_display string to display the message on the LED display.

However when i trigger the call i get the following error. I can send the POST via POSTMAN but not through Chrome as i test my app through WebIDE:

Failed to load resource: the server responded with a status of 401 (Unauthorized) https://iotmmsd2b412a60.us2.hana.ondemand.com/com.sap.iotservices.mms/v1/api/http/push/af55c60f-13fc-47b0-b09d-00f318da5d1d

XMLHttpRequest cannot load https://iotmmsd2b412a60.us2.hana.ondemand.com/com.sap.iotservices.mms/v1/api/http/push/af55c60f-13fc-47b0-b09d-00f318da5d1d. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://webidetesting0272800-d2b412a60.dispatcher.us2.hana.ondemand.com' is therefore not allowed access. The response had HTTP status code 401.

I have configured Destinations as well which i have read are required to avoid this CORS issue but in my case it does not appear to have any effect. See Destintions below:

Name=IoT_MMS_API Description=IoT MMS API Type=HTTP Authentication=BasicAuthentication CloudConnectorVersion=2 ProxyType=Internet URL=https\://iotmmsd2b412a60.us2.hana.ondemand.com/com.sap.iotservices.mms User=XXXXXX

Name=IOT_RDMS_API Description=IOT_RDMS_API Type=HTTP Authentication=BasicAuthentication CloudConnectorVersion=2 ProxyType=Internet URL=

https\://iotrdmsiotservices-d2b412a60.us2.hana.ondemand.com/com.sap.iotservices.dms

User=XXXX

Does anyone know what's missing in order to push messages to a device from a web interface? I think i've followed the documentation to a T but still appear to be missing something. Thanks in advance for your help!

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

2 Answers

preethi ande Feb 22, 2017 at 07:13 AM
0

Hi,

Is this issue resolved? am also facing the same issue, can you tell me how to resolve.

Thanks,

Preethi

Share
10 |10000 characters needed characters left characters exceeded
Anton Levin
Feb 22, 2017 at 09:48 AM
0

I'd recommend to have a look on a StarterKit example [1], where messages are pushed from web application to the device via HTTP, WS and MQTT.

[1] https://github.com/SAP/iot-starterkit/tree/master/src/apps/java/consumption

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

Is there an updated link to this? I get a 404 when attempting to access that page

0
0