The ports on the server I am posting to have been opened, ports 80, 21-25. Why would it refuse my connection?
Here is my code for reference:
- Code: Select all
public HttpResponse doPost(String url, Map<String, String> kvPairs)
throws ClientProtocolException, IOException {
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
if (kvPairs != null && kvPairs.isEmpty() == false) {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
kvPairs.size());
String k, v;
Iterator<String> itKeys = kvPairs.keySet().iterator();
while (itKeys.hasNext()) {
k = itKeys.next();
v = kvPairs.get(k);
nameValuePairs.add(new BasicNameValuePair(k, v));
}
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
}
HttpResponse response;
response = httpclient.execute(httppost);
return response;
}
- Code: Select all
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Map<String,String> vars = new HashMap<String,String>();
HttpResponse response;
String xml = null;
vars.put("login", "admin");
try {
response = doPost("http://myservername/android/login.php",vars);
InputStream is = response.getEntity().getContent();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(20);
int current = 0;
while((current = bis.read()) != -1){
baf.append((byte)current);
}
xml = EntityUtils.toString(response.getEntity());
Toast.makeText(v.getContext(), xml, Toast.LENGTH_LONG).show();
} catch(ClientProtocolException cpe) {
Toast.makeText(v.getContext(), "There was a client issue. Try again later", Toast.LENGTH_LONG).show();
} catch(IOException ioe) {
Toast.makeText(v.getContext(), "There was an IO issue. Try again later", Toast.LENGTH_LONG).show();
Toast.makeText(v.getContext(), ioe.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
Here is the PHP code on the Apache server in login.php (which has full permissions):
- Code: Select all
<?php echo $_POST['login']; ?>
It throws an IOException every time. Any idea why? Thanks for the help, people.