Click here to Skip to main content
15,891,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
#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.
XML
<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>
Posted
Comments
Richard MacCutchan 7-Nov-12 4:14am    
What is the text of the request you are sending?

1 solution

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. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900