In WAMP server the port number was changed to 81 instead of 80 (to be able for another app to run). However, when I attempt to connect to server in which WAMP port number changed, to get data from data base, just my app stopped! I want to set the port-number for connection programmatically. I attempt to do such things which are:
change the proxy setting manually from phone setting itself (which succeeded with me). But, what I am looking for to be able to do that programmatically.
attempt to append Android Proxy Library. (which does not succeed with me) just many errors !
-
attempt to append the prot number with connection call statement, but also this does not work. The call statement is:
try { result=bringData("http://"+IpAddress+"/android_connect/test.php",dbname,dbpass); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }
But when I append port number to IpAddress this does not work also, as for example:
try {
result=bringData("http://192.168.0.20:81/android_connect/test.php",dbname,dbpass);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The code that connect to data-base:
public String bringData(String url, String jsonValue1, String jsonValue2) throws JSONException {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
JSONObject json = new JSONObject();
try {
json.put("dbname",jsonValue1);
json.put("dbpass", jsonValue2);
JSONArray postjson=new JSONArray();
postjson.put(json);
// Post the data:
httppost.setHeader("json",json.toString());
httppost.getParams().setParameter("jsonpost",postjson);
// Execute HTTP Post Request
System.out.print(json);
HttpResponse response = httpclient.execute(httppost);
// for JSON:
if(response != null) {
InputStream is = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
try {
int count=0;
while ((line = reader.readLine()) != null) {
result=line;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
return result; //returned results from php code
}
In sum, If there are any ideas or solutions or source code that can use to change the port number of connection for Android app. please?
Thanks In advance.