为什么要承诺.所有axios帖子,返回400,404错误?



我要做的是在一个函数中发送多个Axios请求。两个请求具有相同的参数。我尝试了不同的方法来实现这一点但它们都出现了相同的错误Request failed with status code 400, Request failed with status code 404

signUp.js

const SignUp = ({ navigation }) => {
const [phoneNumber, setPhoneNumber] = useState('');
let register = "https://api.herokuapp.com/api/v1/auth/register" 
let sendVerification= "https://api.herokuapp.com/api/v1/auth/sendVerification-otp"

const signUp = () => {

const userParams = {
phone: phoneNumber,
};

Promise.all([
axios.post(register, userParams),
axios.post(sendVerification, userParams)
])
.then(response => {
const register1 = response[0].data
const sendVerification1 = response[1].data
})
.catch(err => {
console.log(err.message)
})
}
return(
<View>
<TouchableOpacity style={styles.ButtonSignUp} onPress={signUp}>
<Text style={styles.ButtonText}>SIGN UP</Text>
</TouchableOpacity>
</View>
);
}
export default SignUp;
let register = "https://api.herokuapp.com/api/v1/auth/register" 
let sendVerification= "https://api.herokuapp.com/api/v1/auth/sendVerification-otp"
const registerApi = axios.post(register , userParams );
const verificationApi = axios.post(sendVerification, userParams );
if (Promise && !Promise.allSettled) {
Promise.allSettled = PromiseHelperAllSettled;
}
const [register1 ,sendVerification1 ] = await Promise.allSettled([registerApi, verificationApi]);

最新更新