0

I am trying to manipulate an XML based API (HIKVision camera) from a React Native app.

 fetch('http://username:password@192.168.0.83/PTZCtrl/channels/2/Continuous', {
  method: 'PUT',
  body: '<PTZData><pan>100</pan><tilt>0</tilt><zoom>0</zoom></PTZData>',
  headers: {
    'Content-type': 'text/xml'
  }
})
.then(res=>res.text())
.then(res=>console.log(res))
.catch(e=>{
  console.log(e);
})

This is the error I recieve after running it.

Network request failed - node_modules\react-native\node_modules\whatwg-fetch\fetch.js:441:29 in onerror - node_modules\event-target-shim\lib\event-target.js:172:43 in dispatchEvent - ... 9 more stack frames from framework internals

What I want is to send XML to the server. I have been able to successfully manipulate the API using this curl command. TEST_PTZ.xml contains the same xml string in the above code.

curl -X PUT -T TEST_PTZ.xml --trace-ascii curl.trace  http://username@password@192.168.0.83/PTZCtrl/channels/1/Continuous

I have narrowed it down to not being a CORS issue. I am open to a fix or other suggestions.

Keegan Teetaert
  • 643
  • 6
  • 22
  • I think this might be the culprit. https://stackoverflow.com/a/43691892/3912239 – ahutch May 02 '18 at 00:13
  • It may be helpful to say I am running on an android device. Also I am able to make get requests posted here https://facebook.github.io/react-native/docs/network.html, so it is not restricted. I think it has something to do with the headers or the format of the PUT. – Keegan Teetaert May 02 '18 at 00:24

0 Answers0