无法正确发布到php服务器-React Native [英] Unable to post properly to php sever - React Native
本文介绍了无法正确发布到php服务器-React Native的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在将数据发布到php服务器时遇到问题. 这是我的代码的快照. 有时它可以正常工作并成功发布,有时却不成功.
I am having issues posting data to php server. Here is a snapshot of my code. Sometimes it works and post successfully and sometimes it does not.
< TouchableOpacity
style = {{ fontSize: 18, color: 'white' }}
containerStyle = {{
padding: 8,
marginLeft: 70,
marginRight: 70,
height: 40,
borderRadius: 6,
backgroundColor: 'mediumseagreen'
}}
onPress = {() => {
if (this.state.newTodo == "") {
alert("Please enter a reason for appointment");
return false
}
var query = {
Reason: this.state.newTodo,
BranchRef: this.props.branch,
AppointmentDate: this.props.date,
ToSeeRef: 369,
PatientRef: 63,
AppointmentTimeID: this.props.appointmentTime,
AppointmentPlatform: 2,
Completed: 0
}
console.log(query)
return fetch('url', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(query)
})
// .then((response) => console.log(response))
.then((response) => response.text())
.then((text) => {
if (Platform.OS === 'android') {
text = text.replace(/\r?\n/g, '').replace(/[\u0080-\uFFFF]/g, ''); // If android , I've removed unwanted chars.
}
return text
})
}}
>
<View style={styles.submitButton}>
<Text style={styles.submitButtonText}>BOOK APPOINTMENT</Text>
</View>
</TouchableOpacity >
这是响应的日志
{"_bodyBlob": {"_data": {"__collector": [Object], "blobId": "f90a0dc3-02be-45e6-a600-41a2cc53a9e8", "offset": 0, "size": 89967}}, "_bodyInit": {"_data": {"__collector": [Object], "blobId": "f90a0dc3-02be-45e6-a600-41a2cc53a9e8", "offset": 0, "size": 89967}}, "headers": {"map": {"cache-control": "no-cache, private", "content-length": "89967", "content-type": "text/html; charset=UTF-8", "date": "Thu, 28 Nov 2019 16:35:23 GMT", "phpdebugbar-id": "fcebec1aec584329cabe4020a9122113", "server": "Microsoft-IIS/8.5", "x-powered-by": "ASP.NET", "x-ratelimit-limit": "60", "x-ratelimit-remaining": "59"}}, "ok": false, "status": 500, "statusText": undefined, "type": "default", "url": "https://visioncapital.officemate.ng/api/store_appointment"}
请问我可能做错了什么?
Please what could I be doing wrong?
推荐答案
我能够通过更改应用程序上的日期格式来解决此问题.
I was able to resolve this by changing the date format on my app.
我正在使用react-native-datepicker,并且日期格式与服务器期望的日期格式不同.
I am using react-native-datepicker and the date format was different from what the server was expecting.
<DatePicker
date={this.state.date}
mode="date"
format="YYYY-MM-DD"
confirmBtnText="Confirm"
cancelBtnText="Cancel"
customStyles={{
dateIcon: {
position: 'absolute',
left: 0,
top: 4,
marginLeft: 0
},
dateInput: {
marginLeft: 36,
borderWidth: 0,
right: 0,
color: "grey"
}
}}
onDateChange={(date) => { this.setState({ date:
date }); }}
/>
这篇关于无法正确发布到php服务器-React Native的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文