简单的Android客户端,用于使用改造的REST Web服务-为什么我会得到';无法连接到服务器';错误
我用PHP编写了一个小的RESTfulWebService(问题末尾给出的代码),它位于我的本地XAMPP服务器中。当我在浏览器中使用简单的Android客户端,用于使用改造的REST Web服务-为什么我会得到';无法连接到服务器';错误,android,web-services,rest,retrofit,Android,Web Services,Rest,Retrofit,我用PHP编写了一个小的RESTfulWebService(问题末尾给出的代码),它位于我的本地XAMPP服务器中。当我在浏览器中使用http://localhost/Test8/?name=Java作为URL,我按预期获得以下数据 {"status":200,"status_message":"Book found","data":999} 这意味着Web服务工作正常 然后我继续写了一个Android应用程序,使用改进库来使用这个Web服务。我的代码如下 问题是我得到的输出是无法连接到本地主
http://localhost/Test8/?name=Java
作为URL,我按预期获得以下数据
{"status":200,"status_message":"Book found","data":999}
这意味着Web服务工作正常
然后我继续写了一个Android应用程序,使用改进库来使用这个Web服务。我的代码如下
问题是我得到的输出是无法连接到本地主机/
MainActivity.java:
package tests.retrofitusageone;
import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.mainActivity_textView);
String url = "http://localhost/Test8/index.php?name=Java";
//String url ="https://graph.facebook.com/youtube?fields=id,name,likes&access_token=1541785476124013|sWrV2Qgw_knjFiQheJ_iT5uir84";
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(url).build();
RestInterface restInterface = restAdapter.create(RestInterface.class);
restInterface.get_price(new Callback<RestJsonPojo>() {
@Override
public void success(RestJsonPojo restJsonPojo, Response response) {
textView.setText("Price of the book: " + restJsonPojo.getData());
}
@Override
public void failure(RetrofitError retrofitError) {
String retrofitErrorString = retrofitError.getMessage();
textView.setText(retrofitErrorString);
}
});
}
}
package tests.retrofitusageone;
import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@Generated("org.jsonschema2pojo")
public class RestJsonPojo {
@SerializedName("status")
@Expose
private Integer status;
@SerializedName("status_message")
@Expose
private String statusMessage;
@SerializedName("data")
@Expose
private Integer data;
/**
*
* @return The status
*/
public Integer getStatus() {
return status;
}
/**
*
* @param status
* The status
*/
public void setStatus(Integer status) {
this.status = status;
}
/**
*
* @return The statusMessage
*/
public String getStatusMessage() {
return statusMessage;
}
/**
*
* @param statusMessage
* The status_message
*/
public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}
/**
*
* @return The data
*/
public Integer getData() {
return data;
}
/**
*
* @param data
* The data
*/
public void setData(Integer data) {
this.data = data;
}
}
package tests.retrofitusageone;
import retrofit.Callback;
import retrofit.http.GET;
interface RestInterface {
//@GET("/youtube?fields=id,name,likes&access_token=1541785476124013|sWrV2Qgw_knjFiQheJ_iT5uir84")
@GET("/index.php?name=Java")
void get_price(Callback<RestJsonPojo>callback);
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tests.retrofitusageone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mainActivity_textView" />"
</RelativeLayout>
<?php
//Process client's request (via URL)
header("Content-Type:application/json");
if ( !empty($_GET['name']) ) {
$name = $_GET['name'];
$price = get_price($name);
if (empty($price)) {
//Book not found
deliver_response(200, 'Book not found!', NULL);
} else {
//Send the response with book price
deliver_response(200, 'Book found', $price);
}
} else {
//throw invalid request
deliver_response(400, "Invalid Request", NULL);
}
//API Functions
function get_price($bookRequested) {
$books = array(
'Java' => 999,
'C' => 348,
'PHP' =>500
);
foreach ($books as $book=>$price) {
if ($book == $bookRequested) {
return $price;
}
}
}
function deliver_response($status, $status_message, $data) {
header("HTTP/1.1 $status $status_message");
$response['status'] = $status;
$response['status_message'] = $status_message;
$response['data'] = $data;
$json_response = json_encode($response);
echo $json_response;
}
?>
RestInterface.java:
package tests.retrofitusageone;
import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.mainActivity_textView);
String url = "http://localhost/Test8/index.php?name=Java";
//String url ="https://graph.facebook.com/youtube?fields=id,name,likes&access_token=1541785476124013|sWrV2Qgw_knjFiQheJ_iT5uir84";
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(url).build();
RestInterface restInterface = restAdapter.create(RestInterface.class);
restInterface.get_price(new Callback<RestJsonPojo>() {
@Override
public void success(RestJsonPojo restJsonPojo, Response response) {
textView.setText("Price of the book: " + restJsonPojo.getData());
}
@Override
public void failure(RetrofitError retrofitError) {
String retrofitErrorString = retrofitError.getMessage();
textView.setText(retrofitErrorString);
}
});
}
}
package tests.retrofitusageone;
import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@Generated("org.jsonschema2pojo")
public class RestJsonPojo {
@SerializedName("status")
@Expose
private Integer status;
@SerializedName("status_message")
@Expose
private String statusMessage;
@SerializedName("data")
@Expose
private Integer data;
/**
*
* @return The status
*/
public Integer getStatus() {
return status;
}
/**
*
* @param status
* The status
*/
public void setStatus(Integer status) {
this.status = status;
}
/**
*
* @return The statusMessage
*/
public String getStatusMessage() {
return statusMessage;
}
/**
*
* @param statusMessage
* The status_message
*/
public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}
/**
*
* @return The data
*/
public Integer getData() {
return data;
}
/**
*
* @param data
* The data
*/
public void setData(Integer data) {
this.data = data;
}
}
package tests.retrofitusageone;
import retrofit.Callback;
import retrofit.http.GET;
interface RestInterface {
//@GET("/youtube?fields=id,name,likes&access_token=1541785476124013|sWrV2Qgw_knjFiQheJ_iT5uir84")
@GET("/index.php?name=Java")
void get_price(Callback<RestJsonPojo>callback);
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tests.retrofitusageone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mainActivity_textView" />"
</RelativeLayout>
<?php
//Process client's request (via URL)
header("Content-Type:application/json");
if ( !empty($_GET['name']) ) {
$name = $_GET['name'];
$price = get_price($name);
if (empty($price)) {
//Book not found
deliver_response(200, 'Book not found!', NULL);
} else {
//Send the response with book price
deliver_response(200, 'Book found', $price);
}
} else {
//throw invalid request
deliver_response(400, "Invalid Request", NULL);
}
//API Functions
function get_price($bookRequested) {
$books = array(
'Java' => 999,
'C' => 348,
'PHP' =>500
);
foreach ($books as $book=>$price) {
if ($book == $bookRequested) {
return $price;
}
}
}
function deliver_response($status, $status_message, $data) {
header("HTTP/1.1 $status $status_message");
$response['status'] = $status;
$response['status_message'] = $status_message;
$response['data'] = $data;
$json_response = json_encode($response);
echo $json_response;
}
?>
package tests.unversitusageone;
进口改装.回收;
导入reformation.http.GET;
接口RestInterface{
//@GET(“/youtube?fields=id、name、likes&access_token=1541785476124013 | sWrV2Qgw_knjFiQheJ_iT5uir84”)
@GET(“/index.php?name=Java”)
无效获取价格(回调);
}
清单:
package tests.retrofitusageone;
import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.mainActivity_textView);
String url = "http://localhost/Test8/index.php?name=Java";
//String url ="https://graph.facebook.com/youtube?fields=id,name,likes&access_token=1541785476124013|sWrV2Qgw_knjFiQheJ_iT5uir84";
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(url).build();
RestInterface restInterface = restAdapter.create(RestInterface.class);
restInterface.get_price(new Callback<RestJsonPojo>() {
@Override
public void success(RestJsonPojo restJsonPojo, Response response) {
textView.setText("Price of the book: " + restJsonPojo.getData());
}
@Override
public void failure(RetrofitError retrofitError) {
String retrofitErrorString = retrofitError.getMessage();
textView.setText(retrofitErrorString);
}
});
}
}
package tests.retrofitusageone;
import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@Generated("org.jsonschema2pojo")
public class RestJsonPojo {
@SerializedName("status")
@Expose
private Integer status;
@SerializedName("status_message")
@Expose
private String statusMessage;
@SerializedName("data")
@Expose
private Integer data;
/**
*
* @return The status
*/
public Integer getStatus() {
return status;
}
/**
*
* @param status
* The status
*/
public void setStatus(Integer status) {
this.status = status;
}
/**
*
* @return The statusMessage
*/
public String getStatusMessage() {
return statusMessage;
}
/**
*
* @param statusMessage
* The status_message
*/
public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}
/**
*
* @return The data
*/
public Integer getData() {
return data;
}
/**
*
* @param data
* The data
*/
public void setData(Integer data) {
this.data = data;
}
}
package tests.retrofitusageone;
import retrofit.Callback;
import retrofit.http.GET;
interface RestInterface {
//@GET("/youtube?fields=id,name,likes&access_token=1541785476124013|sWrV2Qgw_knjFiQheJ_iT5uir84")
@GET("/index.php?name=Java")
void get_price(Callback<RestJsonPojo>callback);
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tests.retrofitusageone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mainActivity_textView" />"
</RelativeLayout>
<?php
//Process client's request (via URL)
header("Content-Type:application/json");
if ( !empty($_GET['name']) ) {
$name = $_GET['name'];
$price = get_price($name);
if (empty($price)) {
//Book not found
deliver_response(200, 'Book not found!', NULL);
} else {
//Send the response with book price
deliver_response(200, 'Book found', $price);
}
} else {
//throw invalid request
deliver_response(400, "Invalid Request", NULL);
}
//API Functions
function get_price($bookRequested) {
$books = array(
'Java' => 999,
'C' => 348,
'PHP' =>500
);
foreach ($books as $book=>$price) {
if ($book == $bookRequested) {
return $price;
}
}
}
function deliver_response($status, $status_message, $data) {
header("HTTP/1.1 $status $status_message");
$response['status'] = $status;
$response['status_message'] = $status_message;
$response['data'] = $data;
$json_response = json_encode($response);
echo $json_response;
}
?>
活动\u main:
package tests.retrofitusageone;
import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.mainActivity_textView);
String url = "http://localhost/Test8/index.php?name=Java";
//String url ="https://graph.facebook.com/youtube?fields=id,name,likes&access_token=1541785476124013|sWrV2Qgw_knjFiQheJ_iT5uir84";
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(url).build();
RestInterface restInterface = restAdapter.create(RestInterface.class);
restInterface.get_price(new Callback<RestJsonPojo>() {
@Override
public void success(RestJsonPojo restJsonPojo, Response response) {
textView.setText("Price of the book: " + restJsonPojo.getData());
}
@Override
public void failure(RetrofitError retrofitError) {
String retrofitErrorString = retrofitError.getMessage();
textView.setText(retrofitErrorString);
}
});
}
}
package tests.retrofitusageone;
import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@Generated("org.jsonschema2pojo")
public class RestJsonPojo {
@SerializedName("status")
@Expose
private Integer status;
@SerializedName("status_message")
@Expose
private String statusMessage;
@SerializedName("data")
@Expose
private Integer data;
/**
*
* @return The status
*/
public Integer getStatus() {
return status;
}
/**
*
* @param status
* The status
*/
public void setStatus(Integer status) {
this.status = status;
}
/**
*
* @return The statusMessage
*/
public String getStatusMessage() {
return statusMessage;
}
/**
*
* @param statusMessage
* The status_message
*/
public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}
/**
*
* @return The data
*/
public Integer getData() {
return data;
}
/**
*
* @param data
* The data
*/
public void setData(Integer data) {
this.data = data;
}
}
package tests.retrofitusageone;
import retrofit.Callback;
import retrofit.http.GET;
interface RestInterface {
//@GET("/youtube?fields=id,name,likes&access_token=1541785476124013|sWrV2Qgw_knjFiQheJ_iT5uir84")
@GET("/index.php?name=Java")
void get_price(Callback<RestJsonPojo>callback);
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tests.retrofitusageone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mainActivity_textView" />"
</RelativeLayout>
<?php
//Process client's request (via URL)
header("Content-Type:application/json");
if ( !empty($_GET['name']) ) {
$name = $_GET['name'];
$price = get_price($name);
if (empty($price)) {
//Book not found
deliver_response(200, 'Book not found!', NULL);
} else {
//Send the response with book price
deliver_response(200, 'Book found', $price);
}
} else {
//throw invalid request
deliver_response(400, "Invalid Request", NULL);
}
//API Functions
function get_price($bookRequested) {
$books = array(
'Java' => 999,
'C' => 348,
'PHP' =>500
);
foreach ($books as $book=>$price) {
if ($book == $bookRequested) {
return $price;
}
}
}
function deliver_response($status, $status_message, $data) {
header("HTTP/1.1 $status $status_message");
$response['status'] = $status;
$response['status_message'] = $status_message;
$response['data'] = $data;
$json_response = json_encode($response);
echo $json_response;
}
?>
"
localhost/Test8/index.php:
package tests.retrofitusageone;
import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.mainActivity_textView);
String url = "http://localhost/Test8/index.php?name=Java";
//String url ="https://graph.facebook.com/youtube?fields=id,name,likes&access_token=1541785476124013|sWrV2Qgw_knjFiQheJ_iT5uir84";
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(url).build();
RestInterface restInterface = restAdapter.create(RestInterface.class);
restInterface.get_price(new Callback<RestJsonPojo>() {
@Override
public void success(RestJsonPojo restJsonPojo, Response response) {
textView.setText("Price of the book: " + restJsonPojo.getData());
}
@Override
public void failure(RetrofitError retrofitError) {
String retrofitErrorString = retrofitError.getMessage();
textView.setText(retrofitErrorString);
}
});
}
}
package tests.retrofitusageone;
import javax.annotation.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@Generated("org.jsonschema2pojo")
public class RestJsonPojo {
@SerializedName("status")
@Expose
private Integer status;
@SerializedName("status_message")
@Expose
private String statusMessage;
@SerializedName("data")
@Expose
private Integer data;
/**
*
* @return The status
*/
public Integer getStatus() {
return status;
}
/**
*
* @param status
* The status
*/
public void setStatus(Integer status) {
this.status = status;
}
/**
*
* @return The statusMessage
*/
public String getStatusMessage() {
return statusMessage;
}
/**
*
* @param statusMessage
* The status_message
*/
public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}
/**
*
* @return The data
*/
public Integer getData() {
return data;
}
/**
*
* @param data
* The data
*/
public void setData(Integer data) {
this.data = data;
}
}
package tests.retrofitusageone;
import retrofit.Callback;
import retrofit.http.GET;
interface RestInterface {
//@GET("/youtube?fields=id,name,likes&access_token=1541785476124013|sWrV2Qgw_knjFiQheJ_iT5uir84")
@GET("/index.php?name=Java")
void get_price(Callback<RestJsonPojo>callback);
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tests.retrofitusageone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mainActivity_textView" />"
</RelativeLayout>
<?php
//Process client's request (via URL)
header("Content-Type:application/json");
if ( !empty($_GET['name']) ) {
$name = $_GET['name'];
$price = get_price($name);
if (empty($price)) {
//Book not found
deliver_response(200, 'Book not found!', NULL);
} else {
//Send the response with book price
deliver_response(200, 'Book found', $price);
}
} else {
//throw invalid request
deliver_response(400, "Invalid Request", NULL);
}
//API Functions
function get_price($bookRequested) {
$books = array(
'Java' => 999,
'C' => 348,
'PHP' =>500
);
foreach ($books as $book=>$price) {
if ($book == $bookRequested) {
return $price;
}
}
}
function deliver_response($status, $status_message, $data) {
header("HTTP/1.1 $status $status_message");
$response['status'] = $status;
$response['status_message'] = $status_message;
$response['data'] = $data;
$json_response = json_encode($response);
echo $json_response;
}
?>
从你的android设备上你不应该把你的android设备从你的android设备上你不应该把你的android设备从你的android设备上你不应该把你的android设备上你不应该把你的android设备从你的android设备上你不应该把你的android设备上你不应该把你的android设备从你的android设备上你不应该把你的android设备上你不应该从你的android设备上你不应该把你的android设备上你不应该把你的本地主机上你不应该放你的代码>你的本地主机上你不应该你不应该从你的安你的安你的安你的android>你的安你的android>你的android设备上你不应该你不应该你不应该把你的安你的android>你的安你的安你的android设备上你不应该你不应该把你的本地主机上你不应该你不应该把你的本地主机上你的本地主机##.#.#.###
,而只是您的服务器地址和端口,如。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。我猜问题出在提供服务器url的main活动中
尝试将url更改为
String url = "http://localhost/Test8/";
因为,您已经在RestInterface中编写了它
初始化restadapter时,始终只使用接口类中的基本url和端点。我猜问题出在提供服务器url的MainActivity中
尝试将url更改为
String url = "http://localhost/Test8/";
因为,您已经在RestInterface中编写了它
初始化restadapter时,始终只使用接口类中的基本url和端点。在url中更改localhosthttp://localhost
到服务器PC的IP地址,例如http://192.168.1.22...
更改url中的本地主机http://localhost
到服务器PC的IP地址,例如http://192.168.1.22...
您无法获取localhost,因为您的android应用程序上没有任何服务器,您应该将服务器ip设置为无法获取localhost,因为您的android应用程序上没有任何服务器,您应该将服务器ip设置为