我正在按照 Flutter Networking/HTTP 教程对在我的 localhost:8000 上运行的服务器执行 GET 请求。通过浏览器访问我的本地主机工作正常。当我指向任何真实的 URL 时,这也很好用,例如https://example.com,但是当我指向https://127.0.0.1:8000 时,我收到类似“连接被拒绝”的错误
每次我重新加载应用程序时,上述错误中的端口都会发生变化。我查看了 http 包代码,似乎没有办法为 URL 指定端口。我如何指向我的本地主机,这是我第一次使用 flutter 吗?PS:我在我的手机设备上运行,我的电脑和手机用同一个 wifi 连接,我的网络是私有的。
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:convert';
class MyHomePage extends StatefulWidget {
const MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
static const url = 'http://127.0.0.1:8000/api/membres/';
// static const url = 'http://10.0.2.2:8000/api/membres/';
//static const url = 'http://localhost:8000/api/membres/';
//static const url= "192.168.1...:8000/association/api/membres";
//static const url = …Run Code Online (Sandbox Code Playgroud) 考虑以下android代码,请解决我的问题:我的笔记本电脑上运行REST服务器..我可以从我的浏览器访问该服务器并获得正确的结果......但现在我想从我的android模拟器中使用它也是使用以下代码在我的笔记本上运行..
// String URL = "http://localhost:8080/server/rest/user/1";
String URL = "http://www.google.com";
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(URL);
HttpResponse result = httpclient.execute(request);
Run Code Online (Sandbox Code Playgroud)
在模拟器中,当我将URL作为http://www.google.com传递时,我得到了正确的结果,但是当我使用我的localhost url(上面评论的那个)时,我得到连接拒绝....
WARN/System.err(901): org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:8080 refused
WARN/System.err(901): Caused by: java.net.ConnectException: /127.0.0.1:8080 - Connection refused
Run Code Online (Sandbox Code Playgroud)
如果我在我的浏览器上运行相同的URL它可以工作.你能告诉我为什么localhost url不能在模拟器中工作..?
我在我的PC上安装了一个apache服务器,我在其中托管一个PHP文件.
然后我尝试使用eclipse连接到该文件,但它总是给我以下错误
connection to http://10.0.2.2:8080 refused.
Run Code Online (Sandbox Code Playgroud)
我尝试将地址更改为以下内容,但始终出现类似错误.
http://10.0.2.2
http://127.0.0.1
http://localhost
Run Code Online (Sandbox Code Playgroud)
谁能帮帮我吗.
编辑:仅供参考,我可以毫无问题地访问远程服务器(例如www.mydomain.com).
课程文件:
HttpClient httpclient = new DefaultHttpClient();
Log.d("test","t0");
HttpPost httppost = new HttpPost("http://10.0.2.2:8080/mylibman/data.php");
Log.d("test","t1");
HttpResponse response = httpclient.execute(httppost); // error here
Log.d("test","t2");
Run Code Online (Sandbox Code Playgroud)
Android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.migrationdesk.mylibman"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
Run Code Online (Sandbox Code Playgroud)
错误LogCat:
11-16 02:02:20.803: E/log_tag(1427): Error in http connection org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2:8080 refused
11-16 02:02:20.803: E/log_tag(1427): Error converting result java.lang.NullPointerException: lock == null
11-16 02:02:20.803: E/log_tag(1427): Error parsing data org.json.JSONException: …Run Code Online (Sandbox Code Playgroud) 使用Ionic服务 - 我的Ionic应用程序将我的REST调用数据返回到在localhost上运行的webapi.
但是当我发出Ionic run时,我的REST API调用失败了.error.data是空白的,所以我不知道错误是什么.
我也可以直接在我的浏览器中点击其余调用的api,看到它返回数据.
有人请给我一些关于如何调试这个的指示,或者为什么我的http调用在运行模式下失败?
我正在使用 Firebase Emulator Suite来测试我的 Firebase Cloud Functions,然后再将其部署到生产中。
探索这种方法以从我的 Andriod 设备触发可调用的 firebase 云函数。
我的应用程序在运行时崩溃了。
错误:
java.lang.IllegalStateException:实例已初始化后无法调用 useEmulator()。
错误来源 - FirebaseFirestore.java:
/**
* Modifies this FirebaseDatabase instance to communicate with the Cloud Firestore emulator.
*
* <p>Note: Call this method before using the instance to do any database operations.
*
* @param host the emulator host (for example, 10.0.2.2)
* @param port the emulator port (for example, 8080)
*/
public void useEmulator(@NonNull String host, int port) {
if …Run Code Online (Sandbox Code Playgroud) android firebase firebase-tools google-cloud-functions google-cloud-firestore
我的笔记本电脑中有一个 ASP.net Web API,地址如下:
本地主机:99949
我将它添加到 IIS Express,我可以从同一局域网中的另一台计算机访问我的 web Api,它是这样的:
尼米斯:80
我可以从其他 PC 访问我的 web api,但是当我尝试使用我的 android 设备访问它时,它显示“网页不可用”错误。
我关闭了所有防火墙。
我该怎么做才能解决它?
尝试从Android手机访问位于localhost:8000的laravel服务器。我做了什么:
如果我访问192.168.0.110,则可以从php服务器看到默认页面。但是当尝试连接到该端口时-显示错误页面,提示:
无法访问该网站
在笔记本电脑的浏览器中,我可以访问localhost:8000
我在做什么错 或如何连接?
对于更多操作系统:: Linux Mint和防火墙(ufw)已关闭。
更新 无法解决问题。改用ngrok。ngrok创建一个可公开共享的URL,该URL隧穿到您的localhost:port。
所以我今天正在探索 PWA,并关注了Your First Progressive Web App。它需要 5 分钟并在我的笔记本电脑上工作,但问题是,我不知道如何通过我的手机浏览它。所以我搜索并找到了如何从我的 Android 设备访问我的本地主机?但不幸的是,那里提供的答案对我不起作用。
为什么会这样?PWA 是否需要某种不同的设置?我在这件事上做错了吗?另外,我找不到任何可以带您在移动设备中实际浏览 PWA 的教程。为什么?
我在我的 android 设备上使用 expo 客户端并设置了一个 django 服务器,localhost:8000我正在尝试在 react native 中使用 fetch 访问和端点。我看过如何从我的 Android 设备访问我的本地主机? 你如何在Android模拟器中连接本地主机?以及如何从 Eclipse 中的 Android Emulator 连接到我的 http://localhost Web 服务器,但这不起作用。
我也尝试使用我机器的 ip 地址而不是 localhost,但没有结果。这是一个示例代码
componentDidMount(){
return fetch('http://my-ip-address:8000/restapi/')
.then((response) => {
console.log("success")
response = response.json()
}).catch(error => {
console.error(error)
})
}
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?
因此,我用一些唯一的URL设置了一些虚拟主机,它们在桌面上运行良好。但是,当我在网络上连接移动设备时,它似乎无法正确访问任何东西,但只能访问默认的localhost虚拟主机,而这仅是我拥有的唯一虚拟主机。
我的设置和编码几乎与此相同,只是网站标题不同
虽然该解决方案将我重定向到我的唯一网址,但默认的wordpress网站上缺少图片。
有没有人设法让移动设备完全访问本地主机以外的链接?
我可以毫无问题地从Windows应用程序访问我的Web API服务器.但是,从Android来看,却是另一回事
那为什么会这样?
"localhost"使用错误的东西(在URL中)?我应该使用计算机的名称吗?
字符串(字面意思为" http://localhost:28642/api/Departments/GetCount?serialNum=4242")是否需要逐字逐句?
调用REST方法的Windows应用程序和调用相同REST方法的Android应用程序之间的区别是什么会导致后者失败(连接被拒绝)?
android url-routing asp.net-mvc-routing asp.net-web-api econnrefused
我已经搜索了这个主题,但仍然不知道如何使它工作:(
我有一个SOAP Web服务(ASP.NET),这个地址(在我的localhost上)是http:// localhost:50473/Service1. ASMX
然后我在我的Android设备上有肥皂客户端,我想连接使用服务器的服务.很多人说我无法通过usb线连接,我必须连接到同一个wifi网络并使用内部IP.
好的,现在我的笔记本电脑和Android设备都连接到wifi网络,
我的笔记本电脑得到192.168.43.17
我的Android设备得到192.168.43.26
那么设备如何连接到上面的SOAP服务器?
从我的设备,我使用192.168.43.17:50473/Service1.asmx但没有运气:(
android ×9
localhost ×2
mobile ×2
apache ×1
api ×1
django ×1
eclipse ×1
econnrefused ×1
expo ×1
fetch-api ×1
firebase ×1
flutter ×1
iis ×1
ionic ×1
javascript ×1
laravel-5 ×1
linux ×1
php ×1
react-native ×1
rest ×1
server ×1
url-routing ×1
virtualhost ×1
wamp ×1
wampserver ×1