Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将JSON对象从React Native发送到Laravel服务器?_Json_Laravel_React Native_Post_Axios - Fatal编程技术网

如何将JSON对象从React Native发送到Laravel服务器?

如何将JSON对象从React Native发送到Laravel服务器?,json,laravel,react-native,post,axios,Json,Laravel,React Native,Post,Axios,我想将这些JSON对象发送到API,以便将它们保存在数据库中: JSON对象 来自React Native的Post请求: 当我提交函数时,我有一个500错误代码 拉威尔控制器: 当我尝试用失眠发送此邮件时,它正在工作,那么我应该怎么做 [ { "name": "Michel", "phone": "+213 93 783 28 73", "users_id": "1"

我想将这些JSON对象发送到API,以便将它们保存在数据库中:

JSON对象 来自React Native的Post请求: 当我提交函数时,我有一个500错误代码

拉威尔控制器: 当我尝试用失眠发送此邮件时,它正在工作,那么我应该怎么做

[
    { "name": "Michel", "phone": "+213 93 783 28 73", "users_id": "1"},
    { "name": "Annie", "phone": "+213 93 783 28 72", "users_id": "1"},
    { "name": "Rory", "phone": "+16505551212", "users_id": "1"},
    { "name": "CESI", "phone": "+213 93 783 28 73", "users_id": "1"}
]

通过不同文件中相同或不同的React Native中的Fetch API创建服务 i、 e.service.js

const api_url  = "www.myUrl.com/"
export function submitContact(data) {
    return fetch(api_url+'/api/contact', {
        method: 'POST',
        headers : {
            'Accept' : 'application/json',
            'Content-Type' : 'application/json',
        },
        body: JSON.stringify(data),
    });

}

然后导入并在组件内部调用它

import { SubmitContact} from './service'

export default function Contact({ navigation }) {
    const { user, logout } = useContext(AuthContext)
    const [contact, setContact] = useState([]);
    const [count, setCount] = useState('');
  
    //console.log(utility.con)
    const uticontact = utility.con;

    console.log(uticontact)
      //Send Post Request 
      submitContact(utility.con).then((response) => response.json())
        .then((responseJson) => {
         // perform  some action  on  your  response

        }) ;
   
    };  
[
    { "name": "Michel", "phone": "+213 93 783 28 73", "users_id": "1"},
    { "name": "Annie", "phone": "+213 93 783 28 72", "users_id": "1"},
    { "name": "Rory", "phone": "+16505551212", "users_id": "1"},
    { "name": "CESI", "phone": "+213 93 783 28 73", "users_id": "1"}
]
const api_url  = "www.myUrl.com/"
export function submitContact(data) {
    return fetch(api_url+'/api/contact', {
        method: 'POST',
        headers : {
            'Accept' : 'application/json',
            'Content-Type' : 'application/json',
        },
        body: JSON.stringify(data),
    });

}

import { SubmitContact} from './service'

export default function Contact({ navigation }) {
    const { user, logout } = useContext(AuthContext)
    const [contact, setContact] = useState([]);
    const [count, setCount] = useState('');
  
    //console.log(utility.con)
    const uticontact = utility.con;

    console.log(uticontact)
      //Send Post Request 
      submitContact(utility.con).then((response) => response.json())
        .then((responseJson) => {
         // perform  some action  on  your  response

        }) ;
   
    };