小编pzy*_*iak的帖子

使用 libcurl 更改内容类型

我有这个代码:

#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();

    if(curl)
    {
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
        curl_easy_setopt(curl, CURLOPT_URL, "localhost/rest-v1/devices/did1/tasks");
        curl_easy_setopt(curl,CURLOPT_PORT,22080);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\"hello\" : \"darkness\"}");

        res = curl_easy_perform(curl);

    }

    curl_easy_cleanup(curl);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我在控制台上得到这个打印:

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 22080 (#0)
> POST /rest-v1/devices/did1/tasks HTTP/1.1
Host: localhost:22080
Accept: */*
Content-Length: 16
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 16 out of 16 bytes
< HTTP/1.1 …
Run Code Online (Sandbox Code Playgroud)

c post http libcurl http-headers

2
推荐指数
1
解决办法
7266
查看次数

标签 统计

c ×1

http ×1

http-headers ×1

libcurl ×1

post ×1