小编Yun*_*nus的帖子

在localhost上反应本机android连接后端服务

我有一个由Nodejs处理的注册服务.此服务正在3001端口上运行.我尝试从React Native应用程序连接此服务.但总是回归

ReactNativeJS:[TypeError:网络请求失败]

我的组件和package.json代码如下.此外,我将URL localhost替换为127.0.0.1,它不起作用.当我从Postman测试后端服务正常工作.提供非常常见的异常网络错误,因此很难理解问题的根源.每个React Native开发人员都可以轻松应对此问题.那么问题是由React Native还是Android造成的?

import React, { Component } from 'react';
import {
    TextInput,
    ScrollView,
    Alert,
    TouchableHighlight,
    Text,
    StyleSheet
} from 'react-native';

export default class Register extends Component {
    constructor(props) {
        super(props);
        this.onPress = this.onPress.bind(this);
    }

componentDidMount() {
    this.state = {
        email: '',
        password: '',
        passwordRepetition: '',
        error: '',
        loading: false
    };
}

onPress() {
    fetch('http://127.0.0.1:3001/user/register', {
        method: 'POST',
        headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            email: this.state.email,
            password: this.state.password,
        }),
    }).then(res => {
        console.log(res); …
Run Code Online (Sandbox Code Playgroud)

android fetch react-native

7
推荐指数
1
解决办法
3489
查看次数

Java如何使用locale对字段进行排序?

我试图通过具有特定区域设置的字段对列表进行排序.我如何结合以下陈述?

names.stream().sorted(Comparator.comparing(AClass::getName)).collect(Collectors.toList());

Collator coll = Collator.getInstance(new Locale("tr","TR"));
coll.setStrength(Collator.PRIMARY);
Run Code Online (Sandbox Code Playgroud)

java lambda java-8

2
推荐指数
1
解决办法
848
查看次数

标签 统计

android ×1

fetch ×1

java ×1

java-8 ×1

lambda ×1

react-native ×1