BasicNetwork.performRequest:意外的响应code 500,Android的登记制度 [英] BasicNetwork.performRequest: Unexpected response code 500, Android Registration System

查看:251
本文介绍了BasicNetwork.performRequest:意外的响应code 500,Android的登记制度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始在我的Andr​​oid应用程序的工作,我需要一个登录名和登记制度。我发现androidhive.info的教程,但我不断地得到错误。我使用的是凌空库发送HTTP请求,并在LogCat中的错误与该库。我用我的DigitalOcean服务器的公网IP​​地址,我想是因为在本教程中,他们存储在本地主机的PHP脚本它可能有一些做这一点。这是我用于注册用户的android活动:

I recently started working on my Android app and I needed a login and registration system. I found a tutorial on androidhive.info but I constantly get errors. I'm using a volley library for sending HTTP requests and the error in LogCat is related to that library. I used a public IP address of my server on DigitalOcean and I think it might have something to do with that because in the tutorial they store the php scripts on localhost. This is my android activity used for registering users:

package foi.hr.air.asocijacije.ui;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.Request.Method;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import foi.hr.air.asocijacije.R;
import foi.hr.air.asocijacije.db.SQLiteHandler;
import foi.hr.air.asocijacije.main.AppConfig;
import foi.hr.air.asocijacije.main.AppController;
import foi.hr.air.asocijacije.main.MainActivity;

public class RegisterActivity extends Activity {

private static final String TAG = RegisterActivity.class.getSimpleName();
private Button btnRegister;
private Button btnLinkToLogin;
private EditText inputName;
private EditText inputSurname;
private EditText inputEmail;
private EditText inputPassword;
private EditText inputPasswordRepeated;
private ProgressDialog pDialog;
private SessionManager session;
private SQLiteHandler db;

public void onCreate(Bundle savedBundleInstance) {
    super.onCreate(savedBundleInstance);
    setContentView(R.layout.register);

    inputName = (EditText) findViewById(R.id.name);
    inputSurname = (EditText) findViewById(R.id.surname);
    inputEmail = (EditText) findViewById(R.id.email);
    inputPassword = (EditText) findViewById(R.id.password);
    inputPasswordRepeated = (EditText) findViewById(R.id.passwordCheck);
    btnRegister = (Button) findViewById(R.id.btnRegister);
    btnLinkToLogin = (Button) findViewById(R.id.btnLinkToLoginScreen);

    pDialog = new ProgressDialog(this);
    pDialog.setCancelable(false);

    session = new SessionManager(getApplicationContext());

    db = new SQLiteHandler(getApplicationContext());

    if (session.isLoggedIn()) {
        Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    }

    btnRegister.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String name = inputName.getText().toString();
            String surname = inputSurname.getText().toString();
            String email = inputEmail.getText().toString();
            String password = inputPassword.getText().toString();
            String passwordCheck = inputPasswordRepeated.getText().toString();

            if(name.isEmpty() || surname.isEmpty() || email.isEmpty() || password.isEmpty() || passwordCheck.isEmpty()) {
                Toast.makeText(getApplicationContext(), "Please enter your details", Toast.LENGTH_LONG).show();
            }
            else {
                if (password.equals(passwordCheck)){
                    registerUser(name, surname, email, password);
                }
                else {
                    Toast.makeText(getApplicationContext(), "Passwords don't match", Toast.LENGTH_LONG).show();
                }
            }
        }
    });

    btnLinkToLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), LoginActivity.class);
            startActivity(i);
        }
    });
}

private void registerUser(final String name, final String surname, final String email, final String password) {



    String tag_string_req = "req_register";

    pDialog.setMessage("Registering...");
    showDialog();

    StringRequest strReq = new StringRequest(Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            // TODO Auto-generated method stub
            Log.d(TAG, "Register response: " + response.toString());
            hideDialog();

            try {
                JSONObject jObj = new JSONObject(response);
                boolean error = jObj.getBoolean("error");
                if(!error) {
                    String uid = jObj.getString("uid");
                    JSONObject user = jObj.getJSONObject("user");
                    String name = user.getString("name");
                    String surname = user.getString("surname");
                    String email = user.getString("email");
                    String created_at = user.getString("created_at");

                    db.addUser(uid, name, surname, email, created_at);

                    Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
                    startActivity(intent);
                    finish();
                }
                else {
                    String errorMsg = jObj.getString("errorMsg");
                    Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
                }
            }
            catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            // TODO Auto-generated method stub
            Log.e(TAG, "Registration error: " + error.getMessage());
            Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
            hideDialog();
        }
    }) {
        @Override
        protected Map<String, String> getParams() {
            // TODO Auto-generated method stub
            Map<String, String> params = new HashMap<String, String>();
            params.put("tag", "register");
            params.put("name", name);
            params.put("surname", surname);
            params.put("email", email);
            params.put("password", password);

            return params;
        }
    };
    AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}

private void showDialog() {
    if (!pDialog.isShowing()) {
        pDialog.show();
    }
}

private void hideDialog() {
    if(pDialog.isShowing()) {
        pDialog.dismiss();
    }
}
}

在我的课堂我AppConfig中存储的路径位置,在PHP脚本(公网IP)

In my class AppConfig I stored the path to location where the php scripts are (Public IP)

package foi.hr.air.asocijacije.main;

public class AppConfig {

public static String URL_LOGIN = "http://95.85.57.105/android_login_api/";

public static String URL_REGISTER = "http://95.85.57.105/android_login_api/";
}

这是我收到的LogCat中的错误日志

And this is the error log that I'm getting in LogCat

04-29 11:35:18.440: E/Volley(1742): [180] BasicNetwork.performRequest:   Unexpected response code 500 for http://95.85.57.105/android_login_api/
04-29 11:35:18.916: E/RegisterActivity(1742): Registration error: null

我希望你能帮助我得到这个东西吧,我尝试使用Mozilla的插件的Htt prequester POST方法来尝试将数据存储在我的网上MySQL数据库只是要确保PHP脚本工作正常,但我不知道我应该在JSON格式发送什么样的内容。如果需要的话,我将发布更多的数据,所以你可以明白问题出在哪里。

I hope that you can help me get this thing right, I tried using POST method on Mozilla plugin HttpRequester to try to store data in my online MySQL database just to be sure that the php scripts are working fine, but I don't know what content should I send in JSON format. If needed I will post additional data so you could understand where the problem is.

推荐答案

这难道不是应该是

public static String URL_LOGIN = "http://95.85.57.105/android_login_api/login.php";

public static String URL_REGISTER = "http://95.85.57.105/android_login_api/register.php";

林不知道抛给你的错误是正好404或500,但还是给它一个尝试。

Im not sure whether the error thrown to you is exactly 404 or 500 , But still Give it a try.

这篇关于BasicNetwork.performRequest:意外的响应code 500,Android的登记制度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆