curl-library
Content-Type: application/x-www-form-urlencoded; SendText=say+This+is+a+test&Send=Send
Date: Fri, 14 Jun 2013 19:42:02 +0100
Dear all,
I am wondering how I can send "say+This+is+a+test&Send" to a specified URL?
I retrieved the header file for this using Live Header plugin for Mozilla:
http://208.115.205.106:8075/ServerAdmin/current_console
POST /ServerAdmin/current_console HTTP/1.1
Host: 208.115.205.106:8075
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101
Firefox/21.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://208.115.205.106:8075/ServerAdmin/current_console_send
Authorization: Basic dm9sY29tX3JlbjpSQ2tmNjk2OQ==
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 37
SendText=say+This+is+a+test&Send=Send
HTTP/1.1 200 OK
Server: UnrealEngine UWeb Web Server Build 1047
Content-Type: text/html
Connection: Close
I am connecting to the admin page that requires authentication, like this:
void SendChat(const char * str)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
std::string response;
char data[128];
sprintf(data, "%s/ServerAdmin/current_console_send",
WebAdminURL);
curl_easy_setopt(curl, CURLOPT_URL, data);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "User-Agent:
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_POST, 1);
sprintf(data, "%s:%s", WebAdminUserName, WebAdminPassword);
curl_easy_setopt(curl, CURLOPT_USERPWD, data);
sprintf(data, "UserName=%s&Password=%s", WebAdminUserName,
WebAdminPassword);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookie");
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookie");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
write_to_string);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
res = curl_easy_perform(curl);
if(CURLE_OK == res)
{
char *ct;
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE,
&ct);
if((CURLE_OK == res) && ct)
{
printf("We received Content-Type: %s\n",
ct);
}
curl_easy_cleanup(curl);
}
printf("\n");
printf(response.c_str());
printf("\n");
}
}
Would anyone be kind enough to post an updated function of the above, that
would allow me to pass the function param "str" to the server page, where
the data I would like to send is "SendText=say+This+is+a+test&Send=Send"?
I know it's cheeky to ask, but with a nice example I believe I'll be able to
make many more functions that I require.
Any help is appreciated.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-06-14