灯笼芯 发表于 2016-3-15 23:32:22

Curl:设置代理的地址

本教程演示了如何管理的代理地址HTTP和HTTPS请求并将请求。 Tizen支持开源的 libcurl图书馆通过Curl API。热身熟悉旋度API通过学习基本知识:
[*]初始化旋度初始化使用Curl,deinitialize后使用。
[*]管理代理地址获取和设置HTTP请求的代理地址。
[*]将HTTP请求处理HTTP请求。
初始化旋度


[*]
初始化使用Curl:

[*]使用功能和数据类型的API(在旋度 移动和 可穿戴应用程序),包括 < curl.h > 头文件在您的应用程序。 您还必须添加 < net_connection.h > 头文件的代理地址。#include <curl.h>
#include <net_connection.h>
[*]为上网,使用Curl API添加 http : / /tizen.org/privilege/internet 特权应用程序的清单文件。
[*]初始化使用Curl库和旋度处理 curl_easy_init () 功能:CURL *curl;
CURLcode curl_err;
curl = curl_easy_init();
[*]通过调用创建并初始化一个连接句柄 connection_create () 功能:connection_h connection;
int conn_err;
conn_err = connection_create(&connection);
if (conn_err != CONNECTION_ERROR_NONE)
{
   // Error handling

   return;
}
[*]当不再需要时,清晰的旋度和连接句柄完成HTTP事务:
curl_easy_cleanup(curl);
connection_unset_proxy_address_changed_cb(connection);
connection_destroy(connection);
管理代理地址有两种方法用于获取和设置代理地址:
[*]直接代理的地址,使用 connection_get_proxy () 的函数(在连接管理器API 移动和 可穿戴应用程序):char *proxy_address;
conn_err = connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_address);
[*]设置代理地址,使用 curl_easy_setopt () 函数与 CURLOPT_PROXY 参数:if (conn_err == CONNECTION_ERROR_NONE && proxy_address)
{
   curl_easy_setopt(curl, CURLOPT_PROXY, proxy_address);
}
[*]通知只要代理地址发生变化,注册一个回调的 connection_set_proxy_address_changed_cb () 连接管理器API的函数:
conn_err = connection_set_proxy_address_changed_cb(connection,
                                                   __proxy_address_changed_cb, NULL);
if (conn_err != CONNECTION_ERROR_NONE)
{
   // Error handling

   return;
}
新代理的地址是通过回调参数。 设置代理地址,使用 curl_easy_setopt () 函数与 CURLOPT_PROXY 参数:static void
__proxy_address_changed_cb(const char *ipv4_address,
                           const char *ipv6_address, void *user_data)
{
   curl_easy_setopt(curl, CURLOPT_PROXY, ipv4_address);
}
将HTTP请求将HTTP请求,设置的URL curl_easy_setop () 函数和开始转移 curl_easy_perform () 功能:curl_easy_setopt(curl, CURLOPT_URL, "https://www.tizen.org/");
curl_err = curl_easy_perform(curl);
if (curl_err != CURLE_OK)
{
   // Error handling
}
页: [1]
查看完整版本: Curl:设置代理的地址