curl-library
use libcurl to send http delete request
Date: Wed, 7 Nov 2012 16:33:58 +0800
#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;}
///////////////////////////////////////////////////////////////////////////////
it always return 400.
Collapse | Copy
Code<http://www.codeproject.com/Questions/490432/usepluslibcurlplustoplussendplushttpplusdeleteplus#>
<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>
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-11-07