首页 文章

改进错误:500 Android 中的内部服务器错误

提问于
浏览
0

我使用改造来连接服务器,我的应用程序有登录页面和注销页面在登录期间我从文本框中获取值并使用 POST 请求发送到服务器它工作正常,

public void LoginUser(View v)

{RestAdapter adapter = new RestAdapter.Builder()      
            .setEndpoint(ROOT_URL)
            .build(); 

    WashAPI api = adapter.create(WashAPI.class);

    api.LoginUser(

            Email.getText().toString(),
            Password.getText().toString(),

            //Creating an anonymous callback
            new Callback<Response>() {
                @Override
                public void success(Response result, Response response) {
                    //On success we will read the server's output using bufferedreader
                    //Creating a bufferedreader object
                    BufferedReader reader = null;

                    //An string to store output from the server
                    String output = "";

                    try {
                        //Initializing buffered reader
                        reader = new BufferedReader(new InputStreamReader(result.getBody().in()));

                        //Reading the output in the string
                        output = reader.readLine();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

登录界面

public interface WashAPI {
@FormUrlEncoded
@POST("/xxx/yyy/signin")
public void LoginUser(
        @Field("email") String email,
        @Field("password") String password,

        Callback<Response> callback);

}

这很好用

用我的服务器 API 登录后,它返回一个令牌,在注销时我需要发送令牌,以便我的会话得到体验。

注销代码

public void signout(View v)
{
    Log.d("insidetoken",t);
    RestAdapter adapter = new RestAdapter.Builder()
            .setEndpoint(ROOT_URL)
            .build();
    SignoutAPI api = adapter.create(SignoutAPI.class);
             api.signout(t,
                    new Callback<Response>() {
                        @Override
                        public void success(Response result, Response response) {

                            BufferedReader reader = null;
                            String output = "";
                            try {
                                reader = new BufferedReader(new InputStreamReader(result.getBody().in()));
                                output = reader.readLine();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }

注销界面

public interface SignoutAPI {
@FormUrlEncoded
@POST("/xxx/yyy/zzz/signout")
public void signout(
       @Field("token") String token,
        Callback<Response> callback);

}

我的代码对于 signin 和 sigout 都是一样

但是对于登录它的工作原理和登出它给了我 RETROFIT ERROR:500 INTERNAL SERVER ERROR

但使用 POSTMAN 它工作正常
在此输入图像描述

3 回答

  • 0

    500 内部服务器错误表示服务器端存在问题,您应该使用邮递员进行检查。

    我很确定 Web 服务响应中存在问题,而不是 android 端的代码。

  • 0

    正如评论中所提到的,看起来您正在登录服务中执行某些未在注销服务中执行的操作。

    要解决此问题,请确保在注销服务时检查名为token的 POST 参数。

  • 0

    也许你是以错误的方式给出令牌在我的方式它是**“持票人 TOKEN”** - >在标题中的授权在我的情况下,我将我的参数更改为

    fun setProfileAvatar(token: String,@Part image: MultipartBody.Part) : Single<Message> {
            return apiService.setProfileAvatar("Bearer ${token}",image)
        }
    

相关问题