React 本机 Axios post 请求在 iOS 模拟器中有效,但在物理 phone 中无效
React native Axios post request works in iOS simulator but not physical phone
当前正在客户端添加注册请求
const { email, password } = params;
console.log(params);
const response = await axios.post('http://localhost:8080/api/v1/auth/register', { email: email, password: password });
在模拟器中有效,但在 iPhone 中无效。可能是什么原因?该请求也适用于邮递员
您可以将您的网络服务器配置为 运行 在网络内可访问的 IP 上,或者您可以使用 ngrok 之类的工具将您的网络服务器公开到互联网(尽管这会造成安全风险)。
您还需要确保您没有使用 localhost
作为 API 基础 URL 否则您的 phone 将尝试发送对自身的请求并失败。
当前正在客户端添加注册请求
const { email, password } = params;
console.log(params);
const response = await axios.post('http://localhost:8080/api/v1/auth/register', { email: email, password: password });
在模拟器中有效,但在 iPhone 中无效。可能是什么原因?该请求也适用于邮递员
您可以将您的网络服务器配置为 运行 在网络内可访问的 IP 上,或者您可以使用 ngrok 之类的工具将您的网络服务器公开到互联网(尽管这会造成安全风险)。
您还需要确保您没有使用 localhost
作为 API 基础 URL 否则您的 phone 将尝试发送对自身的请求并失败。