【发布时间】:2014-04-30 11:04:38
【问题描述】:
我正在编写用于发送带有数据的 http 请求的代码。但我不能在特定的 URL 发送数据。我正在使用 curl 进行 http 请求。我可以获得 curl 的全部输出,但到目前为止无法用它发送数据。当我发送请求时,它应该带有一些数据,比如你好。我该怎么做?
#include "stdafx.h"
#include <stdio.h>
#include "curl/curl.h"
#include "curl\easy.h"
int main(void)
{
CURL *curl;
CURLcode res;
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8080/Main/GiveResponse.jsp");
/* Now specify the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "prod1");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
curl_global_cleanup();
system ("pause");
return 0;
}
【问题讨论】:
-
这个程序已经发送数据了。你需要更好地说明它有什么问题......
标签: c++ visual-c++ curl