在WAMP服务器中,端口号已更改为81而不是80(以便能够运行其他应用)。但是,当我尝试连接到WAMP端口号发生变化的服务器时,为了从数据库中获取数据,我的应用程序就停止了!我想以编程方式设置连接的端口号。我试图做以下事情:
从手机设置本身手动更改代理设置(由我成功)。但是,我正在寻找能够以编程方式做到这一点。
尝试附加Android代理库。 (这对我没有成功)只是很多错误!
尝试使用连接调用语句附加prot编号,但是 这也行不通。调用语句是:
try {
result=bringData("http://"+IpAddress+"/android_connect/test.php",dbname,dbpass);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但是当我将端口号附加到IpAddress时,这也不起作用,例如:
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();
}
连接到数据库的代码:
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
}
总之,如果有任何想法或解决方案或源代码可用于更改Android应用的端口连接数。请?
先谢谢。