如何使改造卷曲的要求吗? [英] How to make a CURL request with retrofit?

查看:159
本文介绍了如何使改造卷曲的要求吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个登录。

请求看起来像这样$卷曲-u用户名:密码 https://urlhere.com

The request looks like this $ curl -u "username:PASSWORD" https://urlhere.com

我怎样才能让这个使用改造工作?

How can i make this to work using retrofit?

我试过一个授权头,像request.addHeader(验证,用户名+:+密码);

I tried an authorization header, something like request.addHeader("Authentication", username+":"+password);

任何帮助吗?

推荐答案

您的问题不够明确。
我想这是基本身份验证,就可以使用这样的事情

Your question is not clear enough. I guess that is basic auth, you can use something like this

@FormUrlEncoded
@POST("/login") void login(
        @Header("Authorization") String authorization,
        Callback<?> callback
);



// later when you call it

public static String getBase64String(String value) throws UnsupportedEncodingException {
    return Base64.encodeToString(value.getBytes("UTF-8"), Base64.NO_WRAP);
}

final String auth = "Basic " + getBase64String("user:password");
apiClient.login(auth, callback);

我希望帮助。 :)

i hope that helps. :)

这篇关于如何使改造卷曲的要求吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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