Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C Linux
#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.
<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 6-Nov-12 22:29pm
Comments
Richard MacCutchan at 7-Nov-12 4:14am
   
What is the text of the request you are sending?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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. Smile | :)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 250
1 George Jonsson 175
2 Jochen Arndt 150
3 Kornfeld Eliyahu Peter 149
4 PIEBALDconsult 110
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100