如何从android应用程序连接到我的ASP.NET MVC WEB API
我有一个ASP.NET MVC应用程序和一个UsersController,其中包含get、put、update和delete。 为了从我的internet浏览器调用它,我调用:如何从android应用程序连接到我的ASP.NET MVC WEB API,android,asp.net-mvc,Android,Asp.net Mvc,我有一个ASP.NET MVC应用程序和一个UsersController,其中包含get、put、update和delete。 为了从我的internet浏览器调用它,我调用: http://localhost:46040/api/users 并以xml格式接收所有用户的列表 几天来,我一直试图用一个简单的get用户从我的android应用程序中访问它,但没有任何运气 我做错了什么 从设备运行调试时,我要调用什么IP 如何激活“api/用户” 以下是我的服务器用户控制器获取代码: publi
http://localhost:46040/api/users
并以xml格式接收所有用户的列表
几天来,我一直试图用一个简单的get用户从我的android应用程序中访问它,但没有任何运气
public IEnumerable<UserModel> Get()
{
IQueryable<User> query;
IEnumerable<UserModel> results;
try
{
query = TheRepository.GetAllUsers();
results = query.ToList().Select(s => TheModelFactory.CreateModel(s));
}
catch (Exception ex)
{
Debug.WriteLine("Exception has been caught: " + ex.Message);
throw;
}
return results;
}
任何帮助都将不胜感激:)ksoap2用于Soap webaervice…………谢谢,我的web服务是RESTful API。。
//private final String url = "http://localhost:46040/Api/Users";//tried this from emulator and device, does not work
private final String url = "http://10.0.2.2:46040/Api/Users";//tried this from emulator, does not work
public void GetAllUsers()
{
Thread t = new Thread(){
@Override
public void run() {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse resp = null;
try {
resp = httpClient.execute(httpPost);
HttpEntity entity = resp.getEntity();
String content = entity.getContent().toString();
Log.e("content", content);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
};
};
t.start();
}