我用登录和注册创建了一个应用程序,它应该使用ftpclient通过FTP与服务器连接并将电子邮件和密码发送到服务器中的PHP scritp获取响应,但是当我尝试搜索时它返回null PHP文件
在FTPclient.connect中的我使用远程地址到可以找到文件login.class.php的文件夹
作为登录我使用了用户的用户来连接filezilla,密码相同;
public class BackgroundTask extends AsyncTask<String,Void,String> {
SharedPreferences preferences;
SharedPreferences.Editor editor;
Context context;
BackgroundTask(Context ctx){
this.context = ctx;
}
@Override
protected String doInBackground(String... params) {
preferences = context.getSharedPreferences("MYPREFS", Context.MODE_PRIVATE);
editor = preferences.edit();
editor.putString("flag","0");
editor.commit();
String task = params[0];
if(task.equals("login")){
String loginEmail = params[1];
String loginPassword = params[2];
try {
FTPClient ftpclient = new FTPClient();
ftpclient.connect("ftp://portalpaconstrushop%255C%2524portalpaconstrushop@waws-prod-sn1-123.ftp.azurewebsites.windows.net/site/wwwroot/classes");
ftpclient.login("portalpaconstrushop\\$portalpaconstrushop","kSqygjfGRGP6zgBRGo1ihEzesmGlaC48RH3nn8Bk27Fay5B62q9EaZ5a4r9g");
//send the email and password to the database
OutputStream outputStream = ftpclient.storeFileStream("Login.class.php");
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream,"UTF-8");
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
String myData = URLEncoder.encode("email","UTF-8")+"="+URLEncoder.encode(loginEmail,"UTF-8")+"&"
+URLEncoder.encode("senha","UTF-8")+"="+URLEncoder.encode(loginPassword,"UTF-8");
bufferedWriter.write(myData);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
//get response from the database
InputStream inputStream = ftpclient.retrieveFileStream("Login.class.php");
InputStreamReader inputStreamReader = new InputStreamReader(inputStream,"UTF-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String dataResponse = "";
String inputLine = "";
while((inputLine = bufferedReader.readLine()) != null){
dataResponse += inputLine;
}
bufferedReader.close();
inputStream.close();
ftpclient.disconnect();
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
System.out.println(dataResponse);
editor.putString("flag","login");
editor.commit();
return dataResponse;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
//This method willbe called when doInBackground completes... and it will return the completion string which
//will display this toast.
@Override
protected void onPostExecute(String s) {
String flag = preferences.getString("flag","0");
if(flag.equals("register")) {
Toast.makeText(context,s,Toast.LENGTH_LONG).show();
}
if(flag.equals("login")){
String test = "false";
String name = "";
String email = "";
String[] serverResponse = s.split("[,]");
test = serverResponse[0];
name = serverResponse[1];
email = serverResponse[2];
if(test.equals("true")){
editor.putString("name",name);
editor.commit();
editor.putString("email",email);
editor.commit();
Intent intent = new Intent(context,LogginIn.class);
context.startActivity(intent);
}else{
display("Login Failed...", "That email and password do not match our records :(.");
}
}else{
display("Login Failed...","Something weird happened :(.");
}
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
public void display(String title, String message){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
}
}