Retrofit Post Parameter

前端 未结 6 987
无人共我
无人共我 2020-12-08 06:37

I am implementing login feature and for that using Post request but i am getting error saying

\"retrofit.RetrofitError: com.squareup.okhttp.interna

6条回答
  •  心在旅途
    2020-12-08 07:19

    Try using this

    public interface SafeUserApi {
     @FormUrlEncoded
        @POST("/api/userlogin")
        void getUserLogin(
                @Field("client_id") String id,
                @Field("client_secret") String secret,
                @Field("username") String uname,
                @Field("password") String password,
                Callback cb
        );
    }
    

    Here parm1 is the POST parameter that you will be passing it to the server. This will solve your problem

    in case if you are using PHP u can access the param1 using $uname= $_POST('username');

    EDIT 1:

    retrofit 2.0 version:

    public interface SafeUserApi {
        @FormUrlEncoded
        @POST("/api/userlogin")
        Call  getUserLogin(
                @Field("client_id") String id,
                @Field("client_secret") String secret,
                @Field("username") String uname,
                @Field("password") String password
        );
    }
    

提交回复
热议问题