Reputation: 301
Im tring to do an httpGet from my android app but i get no respond , when i do the same httpGet from the browser it work. i also use the chrome extension Postman to test the URL that i'm sending and it works
@Override
public void onLocationChanged(Location location) {
// Draw the marker, if destination location is not set
latitude = location.getLatitude();
longitude = location.getLongitude();
if (mMarkerPoints.size() < 2) {
mLatitude = location.getLatitude();
mLongitude = location.getLongitude();
LatLng point = new LatLng(mLatitude, mLongitude);
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(point));
mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(18));
drawMarker(point);
}
String Text = "My current Latitude = " + latitude + " Longitude = "
+ longitude;
Thread trd = new Thread(new Runnable() {
@Override
public void run() {
try {
SendQueryString();
} catch (Throwable e) {
e.printStackTrace();
Log.i(".............", "Error");
}
}
});
trd.start();
}
public void SendQueryString() {
String url = //
"http://sistemamedicointegrado.azurewebsites.net/Home/Ubicacion?latitud="
+ latitude + "&longitud=" + longitude + "&id=1".toString().trim();
try {
HttpClient Client = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
Client.execute(httpget);
Log.i(".............", "I am here");
} catch (Exception ex) {
}
}
Upvotes: 2
Views: 246
Reputation: 301
The error was on the server side, the action method from the controller wasn't allowing anonimus Gets.
Upvotes: 2
Reputation: 213
try this code!!!
public void SendQueryString() {
String url = //
"http://sistemamedicointegrado.azurewebsites.net/Home/Ubicacion?latitud="
+ latitude + "&longitud=" + longitude + "&id=1".toString().trim();
try {
HttpClient Client = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
HttpResponse response = Client.execute(httpget);
String result=response.toString();
Log.i("Response", ":"+result);
Log.i(".............", "I am here");
} catch (Exception ex) {
}
}
Upvotes: -1
Reputation: 617
Use AsyncTask and call this method
public int getResponceWithGet(String url) {
int code = 0;
try {
HttpClient hc = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse rp = hc.execute(get);
code= rp.getStatusLine().getStatusCode();
return code;
} catch (IOException e) {
Log.e("calling service", e.toString());
e.printStackTrace();
}
catch(Exception e)
{
Log.e("calling service", e.toString());
}
return code;
}
Upvotes: 0