在React Native中使用XML-RPC

Consuming XML-RPC in React Native

本文关键字:XML-RPC React Native      更新时间:2023-09-26

我正试图使用模拟javascript库在React Native中使用XML-RPC

这是我的代码:

import React, { Component } from 'react';
import {
  AppRegistry,
  View,
  Text
} from 'react-native';
const xmlrpc = require('./mimic');
class TestXmlRpc extends Component {
    constructor (props) {
        super(props);
        var request = new xmlrpc.XmlRpcRequest("http://192.168.43.10:8000", 'add');  
        request.addParam(1);  
        request.addParam(3);  
        var response = request.send();  
        console.log(response.parseXML()); 
    }
}
AppRegistry.registerComponent('TestXmlRpc', () => TestXmlRpc);

但我一直收到错误"不支持同步http请求"我做错了什么?thx大量

您必须更改这样的调用

xhr.open("POST", this.serviceUrl, false);

进入

xhr.open("POST", this.serviceUrl, true);

由于异步现在是必需的