gpt4 book ai didi

android - 无法连接到 localhost/127.0.0.1 android

转载 作者:太空宇宙 更新时间:2023-11-03 13:18:57 25 4
gpt4 key购买 nike

我是 android 开发的新手,正在尝试通过改造库在 android 中调用本地 .NET web api 服务。在 IIS 上启动我的 web api 后,我收到此错误,无法连接到 localhost/127.0.0.1 android。

当我按照建议做同样的事情时 http://themakeinfo.com/2015/04/retrofit-android-tutorial/ , 它工作正常,但是我的本地主机服务没有从 android 调用

我的服务网址是 http://localhost:52511/api/Values/getAllStudents/5

它也在浏览器中以 XML 格式输出。

我也尝试过调用它,

public interface gitapi {
@GET("/api/Values/GetProduct/{id}") //here is the other url part.best way is to start using /
public void getFeed(@Path("id") int id, Callback<gitmodel> response);
}

public class gitmodel {
public int studentId;
public String studentName;
public String studentAddress;
}


String API = "http://10.0.2.2:52511";
public void CallService(View view){

RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(API).build();
gitapi git = restAdapter.create(gitapi.class);

int id = 5;
git.getFeed(id, new Callback<gitmodel>() {
@Override
public void success(gitmodel gitmodel, Response response) {
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_LONG).show();
}

@Override
public void failure(RetrofitError error) {
Toast.makeText(getApplicationContext(), "Errors", Toast.LENGTH_LONG).show();
}
});
}

但没有运气。

请告诉我需要更改哪里才能使其正常工作。 ?

我在浏览器中得到的响应是,

<ArrayOfstudents xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/APICall.Controllers">
<students>
<studentAddress>valsad</studentAddress>
<studentId>1</studentId>
<studentName>Keval</studentName>
</students>
<students>
<studentAddress>Hyderabad</studentAddress>
<studentId>2</studentId>
<studentName>Honey</studentName>
</students>
</ArrayOfstudents>

最佳答案

而不是使用 127.0.0.1:<PORT>使用本地 IP

关于android - 无法连接到 localhost/127.0.0.1 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31623872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com