I'm trying to call my web API endpoints from Android device connected via USB, but I get this error:
failed to connect to /192.168.1.156 (port 7259) from /192.168.1.159 (port 41916) after 10000ms
This is my API call:
LinearLayout loginButtonLL = (LinearLayout) findViewById(R.id.loginButtonLL);
loginButtonLL.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
textViewLoginButtonText.setVisibility(View.GONE);
ProgressBar progressBarLoginButton = findViewById(R.id.progressBarLoginButton);
progressBarLoginButton.setVisibility(View.VISIBLE);
OkHttpClient client = new OkHttpClient();
String url="https://192.168.1.156:7259/api/Login/LoginUser";
Request request = new Request.Builder()
.url(url)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
call.cancel(); <-- ERROR IS HERE
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String myResponse = response.body().string();
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
//txtView.setText(myResponse);
}
});
}
});
}
});
The WebApi:
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace DatezApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class LoginController : ControllerBase
{
[Route("LoginUser")]
[HttpPost]
public async Task<IActionResult> LoginUser()
{
return Ok(new { });
}
}
}