@Limons

Как сделать post request PNG(base64) с помощью curlcpp?

Просьба не обращать внимание на лишнее библиотеки и переменные. Я хотел бы услышать рекомендации и ошибки насчёт библиотеки curl. Правильно ли делаю?

Я отправлю скриншот капчи на сервер RuCaptcha.
Post доходит и я получаю ID моей капчи, но сайт ловит:
61af71b51458d178953801.png

Вот код:
#define CURL_STATICLIB

#include <iostream>
#include <sstream>
#include <curl/curl.h>
#include <string>
#include "base64.h"
#include <fstream>
#include <vector>
#include <cstdio>
using namespace std;



const string URL_in = "http://rucaptcha.com/in.php";

const string URL_res = "http://rucaptcha.com/res.php";


const string file_path = "C:\\png\\captcha\\captcha.png";

const string key = "xxx";
const string method = "base64";
const string phrase = "0";
const string regsense = "0";
const string numeric = "3";
const string calc = "0";
const string min_len = "1";
const string max_len = "4";
const string language = "2";

/*		+
		"&phrase=" + phrase +
		"&regsense=" + regsense +
		"&numeric=" + numeric +
		"&calc=" + calc +
		"&min_len=" + min_len +
		"&max_len=" + max_len +
		"&language=" + language;
*/

string base64_encode_image(const string& path) {
	vector<char> temp;

	ifstream infile;
	infile.open(path, ios::binary);    

	if (infile.is_open()) {
		while (!infile.eof()) {
			char c = (char)infile.get();
			temp.push_back(c);
		}
		infile.close();
	}

	else return "File could not be opened";
	string ret(temp.begin(), temp.end() - 1);
	ret = base64_encode((unsigned const char*)ret.c_str(), ret.size());

	return ret;
}

int main() {

	string data =
		"key=" + key +
		"&method=" + method +
		"&body=" + base64_encode_image(file_path);



	CURL* curl;
	CURLcode res;

	curl_global_init(CURL_GLOBAL_ALL);

	curl = curl_easy_init();

	if (curl) {

		curl_easy_setopt(curl, CURLOPT_URL, URL_in.c_str());
		curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()
		);

		res = curl_easy_perform(curl);

		if (res != CURLE_OK) {
			fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
		}

		curl_easy_cleanup(curl);

	


	}

	curl_global_cleanup();
	return 0;


}
  • Вопрос задан
  • 57 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы