Reputation: 31
I wrote an Android app that sends data to an ASP.NET web site. When I test the app, I get the error:
Connection to
https://localhost:1863
refused.
How do I solve this problem? Also, how do I go about storing this data into SQL Server?
HttpClient client1 = new DefaultHttpClient();
HttpPost request = new HttpPost("http://localhost:1863");
String lat = "lat",lng = "lng";
List<NameValuePair> postParameters = new ArrayList<NameValuePair>(3);
postParameters.add(new BasicNameValuePair("lat", lat));
postParameters.add(new BasicNameValuePair("lng", lng));
try {
request.setEntity(new UrlEncodedFormEntity(postParameters));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
request.setEntity(formEntity);
// request.addHeader("Content-type", "application/x-www-form-urlencoded");
HttpResponse response;
response = client1.execute(request);
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line;
String page = "";
line = in.readLine();
while (line != null)
{
page = page + line;
line = in.readLine();
}
}
catch (ClientProtocolException e) {
e.printStackTrace();} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Upvotes: 1
Views: 1655
Reputation: 31
I made an ASP.NET handler page (.ashx), named it Handler
, and replaced "http://localhost:1863"with"http://localhost:1863/Handler.ashx" and it solved the problem.
Upvotes: -1
Reputation: 41858
You need to get the IP address of your server, rather than using localhost
, since localhost
is local to the calling computer, so the localhost
for the Android is different than for the IIS server.
UPDATE:
Just use IP address 10.0.2.2
, as explained in Stack Overflow question How to connect to my http://localhost web server from Android Emulator in Eclipse.
Upvotes: 2