0

我在我的 android 代码中使用 Java DefaultHttpClient 和基本身份验证:

HttpParams params = new BasicHttpParams();
ConnManagerParams.setTimeout(params, mTimeOut);
HttpConnectionParams.setSoTimeout(params, mTimeOut);
HttpConnectionParams.setConnectionTimeout(params, mTimeOut);
HttpConnectionParams.setTcpNoDelay(params, true);

DefaultHttpClient client = new DefaultHttpClient(params);
client.getCredentialsProvider().setCredentials(
        new AuthScope(getHost(), getPort()),
        new UsernamePasswordCredentials(getId(),getPassword()));

HttpGet httpget = new HttpGet(url);
HttpResponse response = client.execute(httpget);

上面的代码使用 HTTPGet 请求的基本凭据。

我必须用 CURL (libcurl) 调用替换这段代码。

我写了一个示例代码来理解 Libcurl 调用。

curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, webpage);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &page);
res = curl_easy_perform(curl);

但这只是基本的 CURL 调用。如何将上述 http 参数和凭据合并到我的 libcurl 调用中。

我需要知道如何编写/修改上面的 CURL 代码以添加 Authscope 和 USRPSWD 凭据的参数和凭据

4

0 回答 0