2017-10-15 13 views
-1

どのように私はこのURL avmlabs.in/avm_db/check_login.php?x={"email":"[email protected]"} retrofitライブラリを使用してcontructすることができます。私はやり方を知らない。私はretrofitライブラリでは新しいです。retrofitライブラリを使用してこのURLを構築するにはどうすればよいですか?

これは私が

public interface ApiInterface { 

    @POST("check_login.php") 
    Call<Login> checkEmail(@Field("x") String email); 


} 

この1つのモデルクラス

public class Login { 

    public String status_code,status_message,success; 

    public String getStatus_code() { 
     return status_code; 
    } 

    public void setStatus_code(String status_code) { 
     this.status_code = status_code; 
    } 

    public String getStatus_message() { 
     return status_message; 
    } 

    public void setStatus_message(String status_message) { 
     this.status_message = status_message; 
    } 

    public String getSuccess() { 
     return success; 
    } 

    public void setSuccess(String success) { 
     this.success = success; 
    } 
} 

を作成しましたが、私はavmlabs.in/avm_db/[email protected]この応答を得たAPIインタフェースです。

+0

'x = {" email:[email protected] "}'と言うことを意味します。 'x = user @ gmail.com'? – Raghunandan

+0

ええx = {"email": "[email protected]"} – priyadharsini

+0

なぜあなたはサーバー側で変更せず、email = [email protected]で簡単にする必要があるのですか?{ – Raghunandan

答えて

0

方法1:Gson

は、オブジェクトと直接

@POST("check_login.php") 
Call<Login> checkEmail(@Field("x") RequestJson requestJson); 

コールにクラス

public class RequestJson { 
    String email; 
    public RequestJson(String email){ 
      this.email = email; 
    } 
} 

RequestJson requestJson = new RequestJson("[email protected]"); 

変更ApiInterfaceを作成して使用します。

方法2:JSONObject

JSONObject jsonObject = new JSONObject(); 
jsonObject.put("email", "[email protected]"); 
String email = jsonObject.toString(); 

を改造する、この文字列を渡し使用。

+0

I 2番目のメソッドを使用しています.iはこのURLを持っています。http://avmlabs.in/avm_db/check_login.php?x={%22email%22:%[email protected]%22}.howはエンコードされていますか? – priyadharsini

+0

@priyadharsiniもしあなたがjsonをしたいのであれば、それを代わりにクエリparamsとして本文に送りなさい。または単純に '電子メール=ユーザー@ gmail.com'を持っています – Raghunandan

+0

@ Raghunandanしかし、それも動作していません。私のコードですJSONObject jsonObject = new JSONObject(); try { jsonObject.put( "email"、 "[email protected]"); } catch(JSONException e){ e.printStackTrace(); } 文字列email = jsonObject.toString(); Log.e( "email"、String.valueOf(jsonObject)); コール call = apiInterface.checkEmail(jsonObject); – priyadharsini

関連する問題