当我尝试在端口8080上点击我的网络应用程序时,我收到以下错误
错误请求 - 无效主机名
HTTP错误400.请求主机名无效.
我甚至不知道从哪里开始诊断这个问题
我正在尝试从Android执行POST请求以在我的内容中插入一些信息phpmyadmin.
我在用什么
Slim 与phpmyadmin存储的数据库建立连接和查询.Slim post函数对我没有任何问题,因为如果我POST在Postman应用程序上使用它,那么数据就会正确地插入到数据库中.
url可以接受由斜杠分隔的两个参数/.这里有一个例子:
http://localhost:8000/insert/Peter/25
Run Code Online (Sandbox Code Playgroud)
其中我在数据库中插入名为Peter且年龄为25的新用户.
当我尝试使用Volley从Android调用相同的url时出现问题,因为它始终用于onErrorResponse方法.
这是我必须使用Android的请求的代码:
RequestQueue queue = Volley.newRequestQueue(getContext());
String url = "http://localhost:8000/insert/" + name + "/" + age;
StringRequest postRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
Log.d("Response", "works well");
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
Log.d("Response", "" + error.getMessage());
}
}
);
queue.add(postRequest);
Run Code Online (Sandbox Code Playgroud)
但它总是采用这种onErrorResponse方法.
我检查了什么
我注意到我在网址上使用的是以太网适配器IP而不是WIFI. …
考虑以下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) 我正在尝试通过 websocket 和 STOMP 协议构建一个 React Native 消息传递应用程序(对于服务器端,我使用的是 Spring Boot),但我得到了一个非常奇怪的行为。我的代码如下:
...
import SockJS from 'sockjs-client'; // Note this line
import Stomp from 'stompjs';
function ChatScreen() {
// Variables declaration
useEffect(() => {
const socket = new SockJS('http://localhost:8080/chat');
const stompClient = Stomp.over(socket);
const headers = {Authorization: `Bearer ${jwt}`};
stompClient.connect(headers, () => {
stompClient.subscribe(
`/user/${user.username}/queue/messages`, console.log, headers,
);
});
return () => stompClient && stompClient.disconnect();
}, [jwt, user.username]);
...
}
Run Code Online (Sandbox Code Playgroud)
安装上述组件后,我得到:
哎呀!与http://localhost:8080/chat 的连接丢失
然后,如果我将 SockJS 导入行从 更改import SockJS from …
我们现在有一个使用 Retrofit 运行良好的 Android 应用程序。我们正在尝试自动化构建以进行测试和生产发布,以减少人为错误的机会(即开发人员在为生产构建时忘记将基本 URL 指向生产......等)
我注意到 Retrofit 的 Base URL 是在类文件中定义的。有没有什么方法可以让我们将其配置在属性文件或 xml 中,以便我们可以使用 Gradle 脚本来选择要包含在构建中的正确文件?
谢谢