[英]Can't upload data to my Parse Server throught my Android Studio project
I have trouble using my Parse Server that I created using Amazon Web Service.我在使用使用 Amazon Web 服务创建的 Parse 服务器时遇到问题。
I try to add a user through ParseUser in my MainActivity with a Button onClick method but it doesn't work for some reason... The error is: Error: com.parse.ParseRequest$ParseRequestException: i/o failure我尝试使用按钮 onClick 方法在我的 MainActivity 中通过 ParseUser 添加用户,但由于某种原因它不起作用......错误是:错误:com.parse.ParseRequest$ParseRequestException:i/o 失败
It all worked well yesterday btw, but it was in Android Studio version 2.2.1.顺便说一句,昨天一切正常,但它在 Android Studio 版本 2.2.1 中。 But today I want to try it on the updated version 3.4.1.但今天我想在更新的 3.4.1 版本上尝试一下。 I had to modify some lines in the Gradle files but nothing elsewhere so I don't know if it's relevant.我不得不修改 Gradle 文件中的一些行,但其他地方没有,所以我不知道它是否相关。
I don't know either what info you need to help me so I'm gonna put everything that might be implied... Sorry for the very long message我也不知道您需要什么信息来帮助我,所以我将把所有可能暗示的信息都放在...对不起,很长的信息
My MainActivity class:我的主要活动 class:
public class MainActivity extends AppCompatActivity {
public void signUpClick(View view) {
EditText usernameEditText = (EditText) findViewById(R.id.usernameEditText);
EditText passwordEditText = (EditText) findViewById(R.id.passwordEditText);
if (passwordEditText.getText().toString().equals("") || usernameEditText.getText().toString().equals("")) {
Toast.makeText(this, "As username and password are required", Toast.LENGTH_SHORT).show();
} else {
ParseUser user = new ParseUser();
user.setUsername(usernameEditText.getText().toString());
user.setPassword(passwordEditText.getText().toString());
user.signUpInBackground(new SignUpCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.i("test", "Success");
} else {
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.i("test", "Fail. Error : " + e.toString());
e.printStackTrace();
}
}
});
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ParseAnalytics.trackAppOpenedInBackground(getIntent());
}
}
A screenshot of my PuTTY session where I read the info of my server in the config.json:我的 PuTTY session 的屏幕截图,我在 config.json 中读取了我的服务器信息:
[screenshot][1] [截图][1]
My StarterApplication class where I define my server information:我的 StarterApplication class 我在其中定义了我的服务器信息:
public class StarterApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
// Add your initialization code here
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId("myappID")
.clientKey("eXK4EAJ8lO7I")
.server("http://18.191.227.26/parse/")
.build()
);
//ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);
defaultACL.setPublicWriteAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
}
Thank you for your time, please tell me if you need other info.感谢您的宝贵时间,如果您需要其他信息,请告诉我。
com.parse.ParseRequest$ParseRequestException: i/o failure
This means there is a problem with your connection.这意味着您的连接存在问题。 Your parse server may be down or your phone doesn't have internet access.您的解析服务器可能已关闭或您的手机无法访问互联网。
If you are sure you have an internet connection and a working parse server, then its probably your server doesnt have SSL sertificate(which means you are using http instead of https. See: .server("http://18.191.227.26/parse/")
) If you are sure you have an internet connection and a working parse server, then its probably your server doesnt have SSL sertificate(which means you are using http instead of https. See: .server("http://18.191.227.26/parse/")
)
After Android 9(including 9) Android prevents connection to unsafe adresses.(ie http connections) Android 9(包括9个)Android后防止连接到不安全的地址。(即http连接)
Add this line between your application tag in your AndroidManifiest file在您的 AndroidManifiest 文件中的应用程序标记之间添加此行
android:usesCleartextTraffic="true"
You can use this while development phase but I recommend you to switch to https.您可以在开发阶段使用它,但我建议您切换到 https。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.