通过HTTPS POST从wxWidgets应用程序发送反馈数据
我有一个wxWidgets应用程序,希望为用户提供一种简单(实现和使用)、可靠、跨平台和安全的方式提交反馈的方法。在SSL上使用HTTP POST似乎最适合这些要求(尽管我会考虑其他方法的答案)。然而,wxWidgets中对HTTPS的支持似乎有限 以下是我考虑过的一些选项及其存在的问题:通过HTTPS POST从wxWidgets应用程序发送反馈数据,http,ssl,curl,smtp,wxwidgets,Http,Ssl,Curl,Smtp,Wxwidgets,我有一个wxWidgets应用程序,希望为用户提供一种简单(实现和使用)、可靠、跨平台和安全的方式提交反馈的方法。在SSL上使用HTTP POST似乎最适合这些要求(尽管我会考虑其他方法的答案)。然而,wxWidgets中对HTTPS的支持似乎有限 以下是我考虑过的一些选项及其存在的问题: :我找不到SSL/TLS支持。依赖于用户具有正确的邮件配置(sendmail、MAPI) :除SSL/HTTPS支持外的所有功能 当前位置如果它不是不完整的,也不是早已死亡的,那么一切都会发生 :除了复杂的
- :我找不到SSL/TLS支持。依赖于用户具有正确的邮件配置(sendmail、MAPI)
- :除SSL/HTTPS支持外的所有功能
- 当前位置如果它不是不完整的,也不是早已死亡的,那么一切都会发生
- :除了复杂的构建/合并之外的一切(事实上,当前版本无法构建)
- :只需直接链接并调用libcurl即可。这是我确定的解决方案(我有一个工作原型),但它感觉非常非wx,虽然libcurl是跨平台的,但Windows肯定不是它的本机平台,因此它为项目增加了显著的依赖性和构建复杂性
Boost::asio有一个“问题”在于它是Boost(这要么是一个大问题,因为“啊,Boost”,要么不是一个问题,因为“太棒了,Boost!”我决定使用链接到openssl的libCURL。这两个包都可以在大多数Linux系统上使用,并且可以很容易地在Windows和OS X上构建 下面是发送反馈的示例C代码:
#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
int main(int argc, char *argv[])
{
CURL *curl;
CURLcode res;
struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
struct curl_slist *headerlist=NULL;
static const char buf[] = "Expect:";
curl_global_init(CURL_GLOBAL_ALL);
/* Fill in the name field */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "name",
CURLFORM_COPYCONTENTS, "John Doe",
CURLFORM_END);
/* Fill in the comments field */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "comments",
CURLFORM_COPYCONTENTS, "using HTTPS POST\nline 2\nline 3",
CURLFORM_END);
curl = curl_easy_init();
/* initalize custom header list (stating that Expect: 100-continue is not
wanted */
headerlist = curl_slist_append(headerlist, buf);
if(curl) {
/* what URL that receives this POST */
curl_easy_setopt(curl, CURLOPT_URL,
"https://some_host.com/path/feedback.php");
// Uncomment to disable certificate checks
//curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
//curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
res = curl_easy_perform(curl);
printf("Curl result: %d\n", res);
/* always cleanup */
curl_easy_cleanup(curl);
/* then cleanup the formpost chain */
curl_formfree(formpost);
/* free slist */
curl_slist_free_all (headerlist);
}
return 0;
}
下面是接受该帖子的PHP代码示例:
<?php
$recipient = "john@some_host.com";
if (empty($_POST)) {
// We only accpet POSTs
header('HTTP/1.0 403 Forbidden');
exit;
} else {
// Handle a POST
$message .= "Submitted at ".date("F j, Y, g:i a")."\n\n";
$message .= "Name:\n";
$message .= $_POST['name']."\n\n";
$message .= "-------------------------------------------\n\n";
$message .= "Comments:\n\n";
$message .= $_POST['comments']."\n\n";
// Send message to email address
$sent = mail($recipient, "Feedback",
$message, "From: Feedback <noreply@some_host.com>\r\n");
if ($sent) {
?>
<html>
<body>
Got POST and sent email:
<pre><? echo $message; ?></pre>
</body>
</html>
<?php
} else {
// Return an error
header('HTTP/1.0 500 Internal Server Error', true, 500);
exit;
}
}
?>
已收到邮件并已发送电子邮件:
很有趣。Boost有一个低级套接字库,我想这并不奇怪。可能比仅仅使用wxSocket更复杂,但对这个特定项目没有多大好处(同步和一次性)。也许。然后你可能会赢(vs wxSocket)如果/因为boost::asio很容易支持SSL。Openssl是在支持SSL的Windows上构建libcurl或boost::asio的最大挑战。因此,在构建方面没有赢家。
<?php
$recipient = "john@some_host.com";
if (empty($_POST)) {
// We only accpet POSTs
header('HTTP/1.0 403 Forbidden');
exit;
} else {
// Handle a POST
$message .= "Submitted at ".date("F j, Y, g:i a")."\n\n";
$message .= "Name:\n";
$message .= $_POST['name']."\n\n";
$message .= "-------------------------------------------\n\n";
$message .= "Comments:\n\n";
$message .= $_POST['comments']."\n\n";
// Send message to email address
$sent = mail($recipient, "Feedback",
$message, "From: Feedback <noreply@some_host.com>\r\n");
if ($sent) {
?>
<html>
<body>
Got POST and sent email:
<pre><? echo $message; ?></pre>
</body>
</html>
<?php
} else {
// Return an error
header('HTTP/1.0 500 Internal Server Error', true, 500);
exit;
}
}
?>