HostFunction中的异常:来自JS的格式错误的调用:字段大小不同

时间:2019-09-28 17:39:01

标签: android react-native axios

我正在尝试向后端发送发布请求,但应用程序不断抛出此错误:

HostFunction中的异常:来自JS的格式错误的调用:字段大小不同。

[[46,11,46],[1,0,0],[[462], [465,2000,156969121,false],1591]

该服务器已经过测试,当我从命令行使用curl发送时,它确实保存了数据。

这是处理请求的功能

handleComment = async ()=>{
        const {comment, isAuth} = this.state;
        const userToken = await AsyncStorage.getItem('userToken');
        const token = "Token "+ userToken;

        if(isAuth!==null&&isAuth===true){
            if(
                comment!==null&&
                comment!==undefined
            ){

                const endpoint ='http://10.0.2.2:8000/api/comments/create/';
                const payload = {
                    comment: comment,
                    post: [this.props.postID]
                };

                axios.post(endpoint, payload, {
                    headers:{
                        'Auuthorization': token
                    }
                })
                    .then(response =>{
                        if(response!==null&&response!==undefined){

                            Alert.alert('Success', 'Your comment was successfully sent.');
                        }else{
                            Alert.alert('Comment send error', 'Your comment could not be sent.');
                        }

                    }).catch(error=>{
                        console.log(error);
                    })

            }else{
                Alert.alert('Comment send error', 'Please write your comment before sending.');
            }
        }else{
            Alert.alert('Authorization error', 'You need to login before sending a comment.');
        }
    }

0 个答案:

没有答案