Marmalade C++ 中的 HTTP Post 请求
HTTP Post request in Marmalade C++
我有一个 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
但是我正在尝试使用果酱内置的 "IwHTTP.h" 来实现这一点。他们缺乏示例,所以我在弄清楚如何实现这一点时遇到了一些麻烦。这是他们执行 post 请求的示例代码:
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 class 文档: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 数据库设置为通过 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
但是我正在尝试使用果酱内置的 "IwHTTP.h" 来实现这一点。他们缺乏示例,所以我在弄清楚如何实现这一点时遇到了一些麻烦。这是他们执行 post 请求的示例代码:
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 class 文档: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);