Javascript react native:有没有办法使用axios.put?
在我的代码中,我尝试使用axios进行put,但我不确定这是一种方法。 我想知道用put最好的方法是什么。 如您所见,我使用componentdidmount启动putData函数Javascript react native:有没有办法使用axios.put?,javascript,reactjs,react-native,expo,Javascript,Reactjs,React Native,Expo,在我的代码中,我尝试使用axios进行put,但我不确定这是一种方法。 我想知道用put最好的方法是什么。 如您所见,我使用componentdidmount启动putData函数 export default class WaterQualitySamplesScreen extends Component { constructor(props) { super(props); this.state = {}; } // //post/////////////
export default class WaterQualitySamplesScreen extends Component {
constructor(props) {
super(props);
this.state = {};
}
// //post//////////////////////////////////
putData = () => {
const axios = require('axios')
axios.put('https://harigotphat1.mekorot.co.il/m200_orderapprovehub/api/Installation?Platform=fcm&InstallationId=o-ritzhak&Handle=ExponentPushToken[JtL6KhGx8JxPeF3rO005WY]',
{ headers: {
Authorization: 'Bearer ' + "my token"}
})
.then(function (response) {
console.log(response);
})
}
// ///////////////////////////////////
registerForPushNotificationsAsync = async () => {
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
if (status !== "granted") {
alert("No notification permissions!");
return;
}
try {
// Get the token that identifies this device
let token = await Notifications.getExpoPushTokenAsync();
console.log("this is my token:", token);
firebase
.database()
.ref("users/" + "/push_token")
.set(token);
} catch (error) {
console.log(error);
}
};
//////////////
async componentDidMount() {
this.currentUser = await firebase.auth().currentUser;
await this.registerForPushNotificationsAsync();
this.putData();
}
render() {
return (
<View style={styles.screen}>
<TouchableOpacity
onPress={() => {
this.props.navigation.navigate({ routeName: "PLACES" });
}}
style={styles.button}
>
<Text style={styles.textButton}>TODO</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
this.props.navigation.navigate({ routeName: " " });
}}
style={styles.button}
>
<Text style={styles.textButton}>SAID</Text>
</TouchableOpacity>
<View style={styles.InfoTableBottomMainContainer}>
<View style={styles.InfoTableBottomView}></View>
</View>
</View>
);
}
}
那么,axios put到底有什么问题?Axios put应该是这样工作的,您确定您的后端服务器与put one配合良好吗?我需要知道我的azure令牌才能在putData中使用它。这是我使用的thr库的链接:我如何从那里获得我的令牌?
export const axiosPutReq = (url, data, authenticationId) => {
return new Promise((resolve, reject) => {
axios({
method: "put",
url,
data,
headers: {
Authorization: "Bearer " + authenticationId,
"Content-Type": "application/json",
Accept: "application/json"
}
})
.then(response => {
resolve(response.data);
})
.catch(error => {
reject(error);
});
});
};