登录到亚马逊没有浏览器

Login to Amazon without Browser

本文关键字:浏览器 亚马逊 登录      更新时间:2023-10-16

我正在windows下用c++编写一个应用程序,与亚马逊云服务一起工作。我需要在网站上获得授权与特定的数据工作,我想获得访问令牌。问题是,我想,我不使用浏览器获得授权,但我不明白如何。我在项目中使用cURL并发送如下请求:

int main(void) {
CURL *curl;
CURLcode res;
struct curl_slist *list = NULL;
FILE *Response = fopen("Response.txt", "wb+");
curl = curl_easy_init();
if (curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://www.amazon.com/ap/oa?client_id=%MY CLIENT ID%scope=clouddrive:read_all&response_type=token&redirect_uri=http://localhost");
    list = curl_slist_append(list, "Accept: text/html");
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
    curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
    curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, SaveData);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, Response);
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);
    /* Check for errors */
    if (res != CURLE_OK) 
        fprintf(Response, "curl_easy_perform() failed: %sn",
        curl_easy_strerror(res));

    curl_slist_free_all(list);
    /* always cleanup */
    curl_easy_cleanup(curl);
}

当我得到响应时,我有一个带有HTML授权页的文件副本。以下是部分答案/

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
<script type='text/javascript'>var ue_t0=ue_t0||+new Date();</script>
<script type='text/javascript'>
var ue_csm = window,
    ue_hob = +new Date();

如果我不能使用浏览器,而我可以用Web浏览器打开一个小窗口(没有框架)并从服务器接收数据(访问令牌)。文档中没有任何内容(亚马逊文档)。

如果你想让你的应用程序与AWS"对话",你应该使用他们的api,而不是web控制台。API请求是无状态的,并且使用凭据签名,并且不像web控制台那样依赖于身份验证会话。

他们有许多流行语言的官方sdk,但不幸的是没有c++的。所以,除非你在某个地方找到一个,否则你将不得不实现你自己的客户端,但它都是基于HTTP的。

另一个值得一提的是,每个产品都有一个独立的API (EC2S3RDS等)。据我所知,您不可能找到适用于所有AWS产品的一体化API。文档可能也有点稀疏,但大多数产品都覆盖得很好。

好运。div;)