> For the complete documentation index, see [llms.txt](https://easonwang.gitbook.io/web_advance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://easonwang.gitbook.io/web_advance/react-native/network.md).

# Network

範例

```javascript
    fetch(network.API_ENDPOINT, {
      method: 'POST',
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        account: this.state.account,
        password: this.state.password,
      }),
    }).then((response) => response.json())
    .then((res) => {
      console.log(res)
    })
    .catch((error) => {
      console.error(error);
    });
```

> 如果出現Request error，通常是你使用模擬器
>
> 改為如下即可
>
> Genymotion
>
> ```
> http://10.0.3.2
> ```
>
> Android studio emulator
>
> ```
> http://10.0.2.2
> ```
>
> <https://stackoverflow.com/questions/5528850/how-do-you-connect-localhost-in-the-android-emulator>
