I've made a ASP.NET Core Web API (hosted locally IIS Express) and I'm trying to get data from it from my Android app (kotlin), but I always get a "Bad request" or "FileNotFoundException" (depending on which method of getting the data is used). I know I can successfully retrieve data from other web API's, but not for mine.
I also tried googling my problem but with no luck on finding the answer.
Retrieving data from my Web API works from browser (http://localhost:24517/bar?username=smthg&password=smthg)
My C# controller:
[HttpGet]
[Route("[controller]")]
public Bar Authenticate(string username, string password)
{
Bar bar = new Bar();
try
{
var user = context.Users.FirstOrDefault(u => u.Username == username && u.Password == password);
bar = context.Bars.
Include(b => b.Inventory).
ThenInclude(i => i.Items).
Include(b => b.Users.Where(u => u.Id == user.Id)).
ToList().
Find(b => b.Users.ToList().Find(u => u.Id == user.Id) == user);
}
catch (Exception)
{
}
return bar;
}
My kotlin request:
const val URL = "http://192.168.0.13:24517/bar"
const val USERNAME = "username=";
const val PASSWORD = "password=";
class BarRepo : IRepoBar {
override fun getBarByUserAsync(userName: String, password: String): Bar {
val url = "$URL$USERNAME$userName&$PASSWORD$password"
val apiResponse = URL(url).readText()
val obj = Json.decodeFromString<Bar>(apiResponse)
return obj
}
}
Aucun commentaire:
Enregistrer un commentaire