簡體   English   中英

為什么在POST上收到500服務器錯誤?

[英]Why am I getting a 500 server error on POST?

當我運行應用程序時,我無法通過郵寄方法獲取鑰匙(令牌),它向我顯示錯誤(500),並且響應為空,我嘗試了很多次,但找不到正常的解決方案。 為了清楚起見,我將Hometask和代碼放在下面:

所以Hometask是:

創建一頁授權,其中有兩個字段-合作伙伴登錄名和密碼

測試的合作伙伴帳戶:

登錄:登錄

密碼:密碼

1) 授權

http://client-api.instaforex.com/Home/GetAPIUsageInfo

您需要獲取令牌“ RequestMoblieCabinetApiToken”。

請求網址: http : //client-api.instaforex.com/api/Authentication/RequestMoblieCabinetApiToken

方法:開機自檢

請求:

{

“登錄”:“ PARTNER_LOGIN”,

“密碼”:“ PARTNER_PASSWORD”

}

作為響應,您將獲得“密碼”(您的令牌)。

我的代碼:

Api接口

package com.example.instaforexapp.Rest;
import com.example.instaforexapp.Modal.ApiAccount;

import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

public interface InstaForexApi {

    @FormUrlEncoded
    @POST("api/Authentication/RequestMoblieCabinetApiToken")
    Call<ApiAccount> createAccount( @Field("Login") String login,
                                    @Field("Password") String password);

}

ApiClient

package com.example.instaforexapp.Rest;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ApiClient {

    private static final String BASE_URL = "http://client-api.instaforex.com/";

    private static Retrofit retrofit = null;

    public static Retrofit getRetrofit() {
        HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        httpLoggingInterceptor.level(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .addInterceptor(httpLoggingInterceptor)
                .build();
        if (retrofit == null) {

            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(okHttpClient)
                    .build();
        }
        return retrofit;
    }
}

ApiAccount類

import com.google.gson.annotations.SerializedName;

public class ApiAccount {

    @SerializedName("Login")
    private String login;

    @SerializedName("Password")
    private String password;

    public ApiAccount(String login, String password) {
        this.login = login;
        this.password = password;
    }

    public String getLogin() {
        return login;
    }

    public String getPassword() {
        return password;
    }

}

主要活動

import android.support.v7.app.AppCompatActivity;
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 com.example.instaforexapp.Modal.ApiAccount;
import com.example.instaforexapp.Rest.ApiClient;
import com.example.instaforexapp.Rest.InstaForexApi;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {
    private EditText txt_login,txt_password;
    private Button btn_confirm;
    public static final String TAG = "com.MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        txt_login = findViewById(R.id.txt_login);
        txt_password = findViewById(R.id.txt_pass);
        btn_confirm = findViewById(R.id.btn_confirm);
        btn_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String login = txt_login.getText().toString();
                String password= txt_password.getText().toString();
                createAccount(login,password);
                Log.i(TAG, "login :"+login +" password: "+password);

            }
        });


    }

    private void createAccount(String login,String password){
            InstaForexApi api = ApiClient.getRetrofit().create(InstaForexApi.class);
            Call<ApiAccount> call = api.createAccount(login,password);
            call.enqueue(new Callback<ApiAccount>() {
                @Override
                public void onResponse( Call<ApiAccount> call, Response<ApiAccount> response) {
                    if (!response.isSuccessful()){
                        Toast.makeText(MainActivity.this, "Error: "+response.code(),
                                Toast.LENGTH_SHORT).show();
                    }

                    ApiAccount account = response.body();
                    String toast = null;
                    if (account != null) {
                        toast = account.getLogin()+" : " + account.getPassword();
                    }
                    Toast.makeText(MainActivity.this, toast, Toast.LENGTH_SHORT).show();


                }

                @Override
                public void onFailure(Call<ApiAccount> call, Throwable t) {
                    Toast.makeText(MainActivity.this, t.getMessage(),
                            Toast.LENGTH_SHORT).show();

                }
            });


    }
}

請幫助獲得“密碼”

來自服務器的500狀態代碼表示您的服務器目前不可用,因此此問題不會一直存在,因此請與后端團隊更好地溝通以解決此問題。 檢查此鏈接以更好地了解服務器響應中的狀態碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM