[英]Can't send patch request to React Native
The patch request is not sent, the server returns 422 code.补丁请求未发送,服务器返回422码。 The Postman patch works fine.
Postman 补丁工作正常。 Maybe I am not sending the request correctly.Here is my EditingPatientScreen code:
也许我没有正确发送请求。这是我的 EditingPatientScreen 代码:
function EditingPatientScreen({route, navigation}) {
const {item} = route.params;
const [values, setValues] = useState({});
const handleChange = (name, e) => setValues(a => ({
...a,
[name]: e
}));
const onSumbit = (id) => {
console.log(id)
patient.put(id)
.then(({ data }) => {
navigation.navigate("HomeScreen");
console.log(values)
}).catch(e => {
console.log(e);
});
};
return (
<>
<View style={{ flex: 1, backgroundColor: `#ffffffff` }}>
<View style={{ backgroundColor: `#ffffff` }}>
<TextInput
style={[styles.text_input]}
label={"Имя и Фамилия"}
onChangeText={ text =>handleChange("fullname", text)}
value={values.fullname}
autoFocus
/>
<TextInput
style={styles.text_input}
label={" Номер телефона"}
keyboardType="phone-pad"
dataDetectorType={"phoneNumber"}
onChangeText={ text =>handleChange( "phone", text)}
value={values.phone}
autoFocus
/>
<View style={styles.viewButton}>
<View style={styles.buttonContainer}>
<TouchableOpacity style={styles.touchableOpacity} onPress={() => onSumbit(item._id)}>
<Text style={styles.touchableOpacityText}><MaterialIcons name={"done"} size={17}/> Сохранить</Text>
</TouchableOpacity>
</View>
</View>
</View>
</View>
</>
);
}
export default EditingPatientScreen;
Here is my code from patients.js.这是我来自 patients.js 的代码。 I think I did the right thing here
我认为我在这里做了正确的事
import axios from "axios";
export default {
post: values => axios.post('http://localhost:5000/patients', values),
show: id => axios.get('http://localhost:5000/patients/' + id),
get: () => axios.get('http://localhost:5000/patients'),
remove: id => axios.delete('http://localhost:5000/patients/ ' + id),
put: id => axios.patch('http://localhost:5000/patients/ ' + id),
}
How to solve the problem?如何解决问题?
There is an extra space on your URL, it should look like this:您的 URL 上有一个额外的空间,它应该如下所示:
put: id => axios.patch('http://localhost:5000/patients/' + id),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.