I'm really new to C++ I'm trying to do a comparison from a curl request but my problem is that my program always print the body and doesn't enter in the if statement I already searched but since I'm new to C++ I don't know what I must search exactly
#define CURL_STATICLIB
#include <iostream>
#include "curl/curl.h"
#include "httprquest.hpp"
#ifdef _DEBUG
#pragma comment (lib, "libcurl_a_debug.lib")
#else
#pragma comment (lib, "libcurl_a.lib")
#endif
#pragma comment (lib, "Normaliz.lib")
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Wldap32.lib")
#pragma comment (lib, "Crypt32.lib")
#pragma comment (lib, "advapi32.lib")
size_t write_data(void* buffer, size_t size, size_t nmemb, void* userp)
{
return size * nmemb;
}
int auth() {
std::string username = "test";
std::string password = "test";
std::string hwid = "11111";
std::string data = "username=" + username + "&password=" + password + "&hwid=" + hwid;
std::string result;
CURL* curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://test.net/something.php?");
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
//curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
if (result.c_str() == "Access Granted#") {
printf("granted");
return 1;
}
else if (result.c_str() == "Bad Access") {
printf("not granted");
return 2;
}
else if(result.c_str() == "Bad HWIDBad Access") {
printf("hwid error");
return 3;
}else {
printf("had not work");
return 4;
}
int main()
{
auth();
}
I have tried with curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
which doesn't print body but i still can't do comparison I tried curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
which is the same I've tried asking to my friends but they don't know C++ so they can't guide me
how can I do a comparison with website body which only will return Access Granted#
, Bad Access
and Bad HWIDBad Access
EDIT: I missed the else statement I added it and I saw that I always get in to the else statement i'm getting Access Granted# but my if statement won't work