gpt4 book ai didi

mysql - Marmalade C++ 中的 HTTP Post 请求

转载 作者:行者123 更新时间:2023-11-30 22:50:28 27 4
gpt4 key购买 nike

我有一个 MySQL 数据库设置为通过 python 接受名称,如下所示:

class PushNames(tornado.web.RequestHandler):
def post(self):
firstname = self.get_argument('firstname','')
surname = self.get_argument('surname','')
cursor = cnx.cursor()
SQL = """insert into Names values ('""" + str(firstname) + """', '""" + str(surname) + """');"""
cursor.execute( SQL )
cursor.close()

我可以使用 cURL 向其添加名称,如下所示:

curl --data "firstname=John&surname=Smith" http://ip.address/pushnames

不过,我正在尝试使用 Marmalade 内置的“IwHTTP.h”来实现这一点。他们缺乏示例,所以我在弄清楚如何实现这一点时遇到了一些麻烦。这是他们执行发布请求的示例代码:

    theHttpObject->SetRequestHeader("Authorization", buf);
theHttpObject->SetRequestHeader("Cache-Control", "max-age=0");
theHttpObject->SetRequestHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
theHttpObject->SetRequestHeader("Accept-Encoding", "gzip,deflate,sdch");
theHttpObject->SetRequestHeader("Accept-Language", "en-GB");
theHttpObject->SetRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");

if (theHttpObject->Post(HTTP_URI, NULL, 0, GotHeaders, NULL) == S3E_RESULT_SUCCESS)
status = kDownloading;

如果有的话,它只会让我更加困惑。任何帮助或想法将不胜感激。如果有帮助,可以在此处找到他们的 HTTP 类文档:http://api.madewithmarmalade.com/classCIwHTTP.html

最佳答案

想通了。万一有人需要它:

    theHttpObject = new CIwHTTP();
theHttpObject->SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");
char* msg = "firstname=John&surname=Smith";
theHttpObject->Post(HTTP_URI, msg, strlen(msg), GotHeaders, NULL);

关于mysql - Marmalade C++ 中的 HTTP Post 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28326753/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com