如何使用curl请求发送数据
How to send data with curl request
我正在编写用于发送带有数据的http请求的代码。但我不能在特定的URL发送数据。我正在使用curl进行http请求。我可以得到curl的整个输出,但到目前为止还不能用它发送数据。当我发送请求时,它应该用一些数据,比如hello。我该怎么做?
#include "stdafx.h"
#include <stdio.h>
#include "curl/curl.h"
#include "curleasy.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: %sn",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
curl_global_cleanup();
system ("pause");
return 0;
}
它正在工作。。检查您的localhost连接或检查GiveResponse.JSP工作正常,没有任何错误。
相关文章:
- 在 C++/C 中使用 CURL 发出带有数据文件的 GET HTTP 请求
- C++:如何通过 curl 调用使用 HTTP post 请求发送二进制数据(protobuf 数据)
- 错误:请求"数据"中的成员"大小",其非类类型为"int [5]"
- 读取 ICMP 回显请求数据
- 其他数据以及 TCP 连接请求
- 通过HTTP请求从站点检索数据(使用QT5.4的C++)
- 在浏览器中呈现数据之前,是否可以拦截http请求并修改数据(例如使用regex替换内容)?如果是,如何
- 是指向在向函数返回值/参数和类请求传输数据期间复制的内存的指针
- 如何实现消费者生产者,消费者可以请求新的数据
- 如何通过串行端口发送请求从目录中检索数据
- 请求想法 - 如何对具有多行和 3 列的 2d 数组进行排序,维护数据行
- 卷曲,来自请求的不完整数据
- 如何处理错误“vtkTrivialProducer :此数据对象不包含请求的范围”
- 请求后中的二进制数据
- cURL 返回上次请求的数据
- 如何在一个套接字上实现并行请求和响应的非阻塞客户端-服务器通信模型,而不存在数据竞争
- std::ifstream::read()读取的数据少于请求的数据,并设置失败位,原因不明显
- http 请求在 & 符号后剪切数据 &
- 访问 QNetwork请求数据,然后再发送数据
- 通过WinInet请求JSON数据会重复部分数据