I have a problem while accessing asp.net web API through android studio project. My web API connect with the database through Entity Framework. I want to call the list of Merchants through API Merchant Controller from android merchant view. Here is my HttpGet method for Merchant:
public class MerchantController : ApiController
{
private DostiCardDBEntities merchantEntities = new DostiCardDBEntities();
[HttpGet]
public HttpResponseMessage listOfMerchant() {
return Request.CreateResponse(HttpStatusCode.OK, merchantEntities.MerchantTables.ToList());
}
}
I access list of Merchants through AsyncTask doInBackground method i-e
private class ExecuteTask extends AsyncTask<String, Integer, String>{
String jsonText = "";
HttpsURLConnection connection;
@Override
protected String doInBackground(String... strings) {
try {
URL url = new URL("http://169.254.80.80:6040/api/Merchant");
connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
InputStream inputStream = connection.getInputStream();
int byteCharacter;
while ((byteCharacter = inputStream.read()) != -1){
char c = (char) byteCharacter;
jsonText += c;
}
} catch (IOException e) {
e.printStackTrace();
}
finally {
connection.disconnect();
}
return null;
}
@Override
protected void onPostExecute(String s) {
Toast.makeText(getApplicationContext(), jsonText, Toast.LENGTH_LONG).show();
}
}