在通过android应用程序访问本地主机中的php脚本时,我在连接{192.168.43.230:25689,…}上得到了意外的流结束
我正试图在我的手机上从我的android应用程序运行一个php脚本(wamp服务器)。我将手机和电脑连接到同一个网络 响应代码显示403。我禁用了防火墙并添加了useragent在通过android应用程序访问本地主机中的php脚本时,我在连接{192.168.43.230:25689,…}上得到了意外的流结束,php,android,http-status-code-403,Php,Android,Http Status Code 403,我正试图在我的手机上从我的android应用程序运行一个php脚本(wamp服务器)。我将手机和电脑连接到同一个网络 响应代码显示403。我禁用了防火墙并添加了useragent 任何人都能说出错误的可能性是什么。好吧,因为HTTP响应代码是403,这意味着访问被拒绝,这意味着问题更可能发生在web服务器端。您可以检查的几件事是,web服务器是否具有检索您尝试访问的文件的访问/权限 还要检查登录到login.php的路径是否已配置为可在Web服务器配置中访问。用一些简单的静态HTML替换php代
任何人都能说出错误的可能性是什么。好吧,因为HTTP响应代码是403,这意味着访问被拒绝,这意味着问题更可能发生在web服务器端。您可以检查的几件事是,web服务器是否具有检索您尝试访问的文件的访问/权限
还要检查登录到login.php的路径是否已配置为可在Web服务器配置中访问。用一些简单的静态HTML替换php代码时会发生什么?当你尝试在android上的浏览器中打开URL时会发生什么?即使我用html文件替换php,错误仍然是一样的@NineBerryan当你在android上尝试打开浏览器应用程序中的URL时会发生什么?如果你没有testWell的权限,那么这似乎是wamp配置允许从不同计算机访问的问题,这不是一个编程问题。如何检查我的web服务器是否具有权限?因为看起来您正在使用Apache服务器。应该有一些日志文件可以让你更好地了解发生了什么。看起来应该有一个日志文件夹,您可以在其中安装WAMP安装,如果是这样,请查看error.log和access.log,至少可以让您了解发生了什么。
protected String doInBackground(String... params) {
try {
// Enter URL address where your php file resides
url = new URL("http://192.168.43.230:25689/test/login.php");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "exception";
}
try {
// Setup HttpURLConnection class to send and receive data from php and mysql
conn = (HttpURLConnection)url.openConnection();
conn.setRequestProperty("User-Agent", "Mozilla/5.0");
conn.setReadTimeout(READ_TIMEOUT);
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setRequestMethod("POST");
// setDoInput and setDoOutput method depict handling of both send and receive
conn.setDoInput(true);
conn.setDoOutput(true);
// Append parameters to URL
Uri.Builder builder = new Uri.Builder()
.appendQueryParameter("username", params[0])
.appendQueryParameter("password", params[1]);
String query = builder.build().getEncodedQuery();
// Open connection for sending data
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(query);
writer.flush();
writer.close();
os.close();
conn.connect();
} catch (IOException e1) {
// TODO Auto-generated catch block
return e1.getMessage();
//return "exception";
}
try {
int response_code = conn.getResponseCode();
// Check if successful connection made
if (response_code == HttpURLConnection.HTTP_OK) {
// Read data sent from server
InputStream input = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
// Pass data to onPostExecute method
return(result.toString());
}else{
return Integer.toString(response_code);
//return("unsuccessful");
}