使用libcurl发送http删除请求 [英] use libcurl to send http delete request
本文介绍了使用libcurl发送http删除请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <stdio.h>
#include <curl/curl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string>
#include <iostream>
using namespace std;
string g_buf = "";
size_t http_callback(void *buffer, size_t size, size_t count, void *user_p)
{
g_buf += (char*)buffer;
return size*count;
}
int main(void)
{
CURL *curl;
CURLcode res;
struct stat file_info;
double speed_upload, total_time;
FILE *fd;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl,CURLOPT_CUSTOMREQUEST,"delete");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,&http_callback);
curl_easy_setopt(curl, CURLOPT_URL,"http://ucenter.local.ucloud.cn/api/aiotest/test");
curl_easy_setopt(curl,CURLOPT_POSTFIELDS,"username=huancong&password=doyou");
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
}
else {
cout<<"receive data:"<<endl<<g_buf<<endl;
}
curl_easy_cleanup(curl);
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
它总是返回400.
///////////////////////////////////////////////////////////////////////////////
it always return 400.
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.2.4</center>
</body>
</html>
推荐答案
谢谢,但是我找到了答案.
更改"curl_easy_setopt(curl,CURLOPT_CUSTOMREQUEST,"删除);"
curl_easy_setopt(curl,CURLOPT_CUSTOMREQUEST,"DELETE");
谢谢你的回答. :)
thanks, but i had found out the answer .
change "curl_easy_setopt(curl,CURLOPT_CUSTOMREQUEST,"delete");"
curl_easy_setopt(curl,CURLOPT_CUSTOMREQUEST,"DELETE");
thanks for you answer. :)
这篇关于使用libcurl发送http删除请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文