是否有可能将CURLOPT_USERPWD转换为我可以在我的Android http客户端中粘贴在HTTP POST消息中的内容?

emi*_*001 2 android http

目前,我正在为Pinterest开发Android应用程序.我要做的是从pinterest(他们只是拉动他们的API页面)获取OAuth令牌.我发现有人的PHP脚本似乎允许某人使用以下方法登录:

function fetch_access_token($client_id, $client_secret, $username, $password) {
        $ch=curl_init();
        curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);                                                
        $post= array(
            "grant_type" => 'password',
            "scope"  => "read_write",
        );
        $host = "https://api.pinterest.com";
        $endpoint = "/oauth/2/access_token?client_id=$client_id&client_secret=$client_secret";
        $request_url = $host . $endpoint;
        curl_setopt($ch, CURLOPT_URL, $request_url);
        curl_setopt($ch, CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
        $s=curl_exec($ch);
        $info = curl_getinfo($ch);
        curl_close($ch);
        if ($info['http_code'] >= 200 and $info['http_code'] < 300) {
            list($junk, $access_token) = explode('=', $s, 2);
            $this->access_token = $access_token;
        } 
        return $s;
    }
Run Code Online (Sandbox Code Playgroud)

如您所见,在此函数的第三行中,CURLOPT_USERPWD用作curl post选项.我已经编写了一个HttpClient包装器库,我正用它来发出请求.我可以轻松添加HTTP POST参数,但是,我不知道要添加什么CURLOPT_USERPWD.我google了一下,没有找到任何有用的东西.

所以,主要的问题是,什么NameValuePair名称通常应该与PHP相对应CURLOPT_USERPWD?第二个问题是,如果这是一个合法的问题,还是我在这里咆哮错误的树?看起来如果它是PHP/Curl可以处理的东西,我应该能够以某种方式将它破解到我的应用程序中.

Ani*_*udh 6

这是授权标题.

因此对于Basic方法,它将是"用户名:密码"的base64编码值,前面带有"Basic".例如,

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Run Code Online (Sandbox Code Playgroud)