我是 android 开发的新手,并尝试通过改造库调用 android 中的本地 .NET Web api 服务。在 IIS 上启动我的 Web api 后,我收到此错误无法连接到 localhost/127.0.0.1 android。
当我按照建议做同样的事情时http://themakeinfo.com/2015/04/retrofit-android-tutorial/ http://themakeinfo.com/2015/04/retrofit-android-tutorial/,工作正常,但我的本地主机服务没有从 android 调用
我的服务网址是,http://localhost:52511/api/Values/getAllStudents/5 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)