Итак, у меня есть приложение, которое имеет функцию регистрации, когда пользователь нажимает «зарегистрировать», программа должна подключиться к серверу Apache MySQL и вставить данные в базу данных phpMyadmin, однако я получаю ошибку, указанную ниже.
logcat:
2020-04-04 21:43:52.035 28854-28854/com.example.blooddonorsystem I/AssistStructure: Flattened final assist data: 3736 bytes, containing 1 windows, 16 views
2020-04-04 21:44:17.157 28854-28854/com.example.blooddonorsystem I/AssistStructure: Flattened final assist data: 3736 bytes, containing 1 windows, 16 views
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: com.android.volley.NoConnectionError: java.net.SocketException: socket failed: EPERM (Operation not permitted)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:177)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: Caused by: java.net.SocketException: socket failed: EPERM (Operation not permitted)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at java.net.Socket.createImpl(Socket.java:492)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at java.net.Socket.getImpl(Socket.java:552)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at java.net.Socket.setSoTimeout(Socket.java:1180)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:143)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:116)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:186)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:262)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.toolbox.HurlStack.addBody(HurlStack.java:259)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:247)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:219)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:97)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:131)
2020-04-04 21:44:17.407 28854-28854/com.example.blooddonorsystem W/System.err: ... 2 more
Вот код для подключения к серверу:
//taken out the real url for obvious reasons
static String URL_REGIST = "http://192.xxx.xxx.xxx/android/register.php";
@Override
public void onClick(View view) {
if(!validate()) return;
Register();
}
private void Register()
{
//make button invisible and make loading widget visible
loading.setVisibility(View.VISIBLE);
registerButton.setVisibility(View.GONE);
//get inputs and convert to strings
final String name = this.nameInput.getText().toString().trim();
final String emailAddress = this.emailAddressInput.getText().toString().trim();
final String password = this.passwordInput.getText().toString().trim();
// final String confirmPassword = this.confirmPasswordInput.getText().toString().trim();
final String postalAddress = this.addressInput.getText().toString().trim();
final String phoneNumber = this.nameInput.getText().toString().trim();
// final int phoneNumber = Integer.parseInt(this.nameInput.getText().toString().trim());
final String bloodType = bloodTypeInput.getSelectedItem().toString().trim();
//start sending data to the database
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_REGIST,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try
{
JSONObject jsonObject = new JSONObject(response);
String success = jsonObject.getString("success");
if(success.equals("1"))
{
Toast.makeText(RegisterActivity.this, "Registration Successful", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(RegisterActivity.this, "Registration Error! Error inserting values to db" + e.toString(), Toast.LENGTH_SHORT).show();
loading.setVisibility(View.GONE);
registerButton.setVisibility(View.VISIBLE);
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(RegisterActivity.this, "Registration Error! error connecting to db " + error.toString(), Toast.LENGTH_SHORT).show();
error.printStackTrace();
loading.setVisibility(View.GONE);
registerButton.setVisibility(View.VISIBLE);
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<>();
params.put("name",name);
params.put("emailAddress",emailAddress);
params.put("password",password);
params.put("postalAddress",postalAddress);
params.put("phoneNumber",phoneNumber);
params.put("bloodType",bloodType);
return params;
}
};
Я уже добавил в мой файл AndroidManifest.
Я использую цифровую каплю Ubuntu для размещения сервера, есть ли какие-либо настройки, которые мне нужно изменить, кроме разрешения доступа через брандмауэр.