Uploading to pastebin

Uploading to pastebin

本文关键字:pastebin to Uploading      更新时间:2023-10-16

简单而简单:我正在生成数据库中的整数列表,我需要将其上传到pastebin.com。这是我的代码:

curl_global_init(CURL_GLOBAL_ALL);
if (CURL* curl = curl_easy_init()) {
    std::ostringstream postField;
    postField << "api_user_key=" << "&" << "api_option=paste" << "&" << "api_paste_private=1" << "&";
    postField << "api_paste_name=GuidSet" << "&" << "api_paste_expire_date=10M" << "&";
    postField << "api_paste_format=text" << "&" << "api_dev_key=XXXXXXXXXXXXXXXX" << "&" << "api_paste_code=";
    for (std::set<uint32>::const_iterator itr = resultSet.begin(); itr != resultSet.end(); ++itr) {
        postField << *itr;
        if (itr != --resultSet.end())
            postField << ",";
    }
    struct MemoryStruct chunk;
    chunk.memory = (char*)malloc(1);
    chunk.size   = 1;
    curl_easy_setopt(curl, CURLOPT_URL, "http://pastebin.com/api/api_post.php");
    curl_easy_setopt(curl, CURLOPT_POST, 1);
    char* postStr = curl_easy_escape(curl, postField.str().c_str(), postField.str().length());
    printf("POST parameters: %sn", postStr);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postStr);
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
    curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&chunk);
    curl_easy_setopt(curl, CURLOPT_USERAGENT, "TrinityCore GuidBot/1.0");
    curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    self->_parentThread.sendCommand("PRIVMSG %s :%s: Finished, data available at %s",
        searchParams.targetRoom.c_str(), searchParams.actionInvoker.c_str(), chunk.memory);
    if (chunk.memory)
        free(chunk.memory);
    curl_free(postStr);
}
curl_global_cleanup();

但是,执行该代码时,我总是明白:

* About to connect() to pastebin.com port 80 (#0)
*   Trying 72.20.36.113...
* connected
* Connected to pastebin.com (72.20.36.113) port 80 (#0)
> POST /api/api_post.php HTTP/1.1
User-Agent: TrinityCore GuidBot/1.0
Host: pastebin.com
Accept: */*
Content-Length: 609
Content-Type: application/x-www-form-urlencoded
* upload completely sent off: 609 out of 609 bytes
< HTTP/1.1 200 OK
< Server: nginx
< Date: Sun, 28 Oct 2012 11:21:33 GMT
< Content-Type: text/html
< Transfer-Encoding: chunked
< Connection: keep-alive
< Vary: Accept-Encoding
<
* Connection #0 to host pastebin.com left intact
* Closing connection #0
Bad API request, invalid api_option

我显然做错了吗?应该粘贴的块必须看起来像" 48,50,59,...等"

我自己解决了,问题不是在卷发中,而是在流参数中,尽管printf'ing diques并未显示任何空间。