ios - 在 react js 中使用 Web Api
问题描述
我正在尝试在 React Js 中使用 Web Api,它没有与它连接,但是这个 Api 在 Android 项目上运行良好,你能帮我解决问题或更好的方法吗,我不知道 react js ..这是我正在工作的代码..它基本上是用于注册用户
获取 API 的代码
const createAccount = function(
email,
password,
title,
firstname,
lastname,
middlename,
mobileno,
businessname,
abn,
dob
) {
//return fetch(`${Constants.baseURL}api/Thetaxfactor/Post`, {
return fetch('http://webservice.thetaxfactorapp.com.au/api/TheTaxfactor/Post', {
method: 'Get',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
//'Accept': 'application/json',
// 'Content-Type': 'application/json',
},
body: HttpUtil.toEncodedForm({
email,
password,
title,
firstname,
lastname,
middlename,
mobileno: .isUndefined(mobileno) || .isNull(mobileno) || _.isNil(mobileno) || mobileno === "null" ? "" : mobileno,
businessname,
abn,
dob,
}),
});
};
onPress 代码
onPress() {
// call getValue() to get the values of the form
const value = this.refs.form.getValue();
if (value) {
const title = value.title;
const firstname = value.firstName;
const middlename = _.isNull(value.middleName) ? '' : value.middleName;
const lastname = value.surname;
const businessname = _.isNull(value.businessName) ? '' : value.businessName;
const password = value.password;
const dob = moment(value.dateOfBirth).format(Constants.API_DATE_FORMAT);
const email = value.emailAddress;
const mobilenumber = value.mobileNumber;
const businessabn = _.isNull(value.businessABN) ? '' : value.businessABN;
this.setState({ loading: true });
Auth.createAccount(
email,
password,
title,
firstname,
lastname,
middlename,
mobilenumber,
businessname,
businessabn,
dob
)
.then(response => {
this.setState({ loading: false });
setTimeout(() => {
if (response.status !== 201) {
// could not login
Alert.alert(
'Cannot Create Account',
'Email address may already be in use, or password is too short (8 characters minimum)',
[
{
text: 'RETRY',
},
],
{
cancelable: true,
}
);
} else {
Alert.alert('Account Created', 'Log in to continue to the main menu');
this.props.navigation.goBack();
}
}, 250);
})
.catch(error => {
this.setState({ loading: false });
Alert.alert(
'Cannot Create Account',
'No internet connection available',
[
{
// 'No internet connection available', [{
text: 'OK',
},
],
{
cancelable: true,
}
);
});
}
}
解决方案
推荐阅读
- .net-assembly - 装配说明 最大尺寸
- sql - Mod功能和选择
- c# - 创建可重用的 WPFToolkit 控件
- reactjs - Expo导入错误:不变的违规元素类型无效预期字符串(用于内置组件)
- c# - 使文本网格中的文本停留几秒钟
- java - 从单个整体式 springboot 应用程序对两个独立数据库中的表执行写入操作
- amazon-ec2 - 如何在 AWS 子网中创建 gRPC 网络连接?
- matlab - csvread 函数加载 0 个值
- meteor - 在 2019 年及以后,如何将 Bootstrap 4 主题和外部 JS Lib 文件与 MeteorJS 正确集成?
- android - 如何从谷歌登录获取身份验证令牌?