如何将参数发送到Webservise?

时间:2019-02-18 06:42:34

标签: xml react-native

我发送2个参数“用户名,密码”,但总是出现错误。我不知道我在哪里弄错了。我在网上搜索,但找不到解决方案。

我在下面显示我的代码和错误。

这是我的代码:

export default class Login extends Component {

    state= {
        username: '',
        password: '',
        leader: [],
    }

    controlall(){

        let collection={}

        collection.username = this.state.username,
        collection.password = this.state.password

        console.warn(collection);


        fetch('url', {
            method: 'POST',
            headers: new Headers({
                        'Content-Type': 'application/soap+xml', // <-- Specifying the Content-Type
                }),
            body: JSON.stringify(collection) // <-- Post parameters
            })
            .then((response) => response.text())
            .then((result) => console.log("sonuç", result))
            // .then((responseText) => {
            // alert(responseText);
            // })
            .then((responresult) => this.setState({leader: responresult}))
            .catch((error) => {
                console.error(error);
            });
    }

这是我得到的错误:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">Server was unable to process request. ---&gt; Data at the root level is invalid. Line 1, position 1.</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>

0 个答案:

没有答案