I want to simulate web form submission to the PHP API, but it fails, I tried a lot of methods. My code
#define HADES "Content-Type:application/x-www-form-urlencoded;charset=utf-8"
int SendPacket(char *packet, const char *server)
{
curl_global_init(CURL_GLOBAL_ALL);
CURL *curl = curl_easy_init();
if (!curl) {
return -1;
}
CURLcode ret;
struct curl_slist *haderlist = NULL;
struct curl_httppost *post = NULL;
struct curl_httppost *last = NULL;
haderlist = curl_slist_append(haderlist, HADES);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "username",
CURLFORM_COPYCONTENTS,
"11111111111", CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "password",
CURLFORM_COPYCONTENTS,
"111111", CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_COPYNAME, "client", CURLFORM_FILE,
"wap", CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, haderlist);
curl_easy_setopt(curl, CURLOPT_URL, server);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
//SendData
ret = curl_easy_perform(curl);
if (ret != CURLE_OK ) {
curl_easy_strerror(ret);
return -1;
}
return 0;
}
I changed the parameter of post to this format and it can be sent normally like this: username = 11111 & password = 1111 & client = wap instead of using the form_add function, but I do n’t know how to do this.
How to correct this problem? I have no idea