gsoap处理http post和http get
来源:互联网 发布:无网络免费单机斗地主 编辑:程序博客网 时间:2024/06/09 16:09
HTML的页面的写法
根据用户需求是想要使用POST还是GET,则在form表单的mothd赋值为post或者getpost:<form action="calc" method="post" name="Calc">get:<form action="calc" method="get" name="Calc">
http_post,http_get插件函数
gsoap自带post和get的插件,路径:gsoap-2.8/gsoap/plugin/httppost.c httpget.c在两个文件中定义了两个重要的函数,http_post,http_get这两个函数用于被作为插件调用,
在gsoap的主函数中用如下方法调用:
/* Register HTTP GET plugin */ if (soap_register_plugin_arg(&soap, http_get, (void*)http_get_handler)) soap_print_fault(&soap, stderr); /* Register HTTP POST plugin */ if (soap_register_plugin_arg(&soap, http_form, (void*)http_form_handler)) soap_print_fault(&soap, stderr);
插件的作用就是当用户的请求是POST时就会自动调用http_form_handler,否则调用http_get_handler
http_get_handler和http_form_handler请求解析函数
其中(void*)http_get_handler和(void*)http_form_handler是需要自定义的函数int http_get_handler(struct soap*); /* HTTP get handler */int http_form_handler(struct soap*); /* HTTP form handler */
在这两个函数中需要解析用户的请求,得到用户请求的路径是什么,其中soap->path就是路径,如下代码
if (!strcmp(soap->path, "/calc")) return calcget(soap );
当路径是”/calc“就调用calcget函数处理请求。
请求处理函数
如上面的函数calcget(soap)如果函数是被http_form_handler调用则需要在函数中使用form(soap)函数解析用户请求中的参数
如果函数是被http_get_handler调用则需要在函数中使用query(soap)函数解析用户请求中的参数
实例:
int calcpost(struct soap *soap){ int o = 0, a = 0, b = 0, val; char buf[256]; char *s = form(soap); /* get form data from body */ while (s) { char *key = query_key(soap, &s); /* decode next key */ char *val = query_val(soap, &s); /* decode next value (if any) */ if (key && val) { if (!strcmp(key, "o")) o = val[0]; else if (!strcmp(key, "a")) a = strtol(val, NULL, 10); else if (!strcmp(key, "b")) b = strtol(val, NULL, 10); } } switch (o) { case 'a': val = a + b; break; case 's': val = a - b; break; case 'm': val = a * b; break; case 'd': val = a / b; break; default: return soap_sender_fault(soap, "Unknown operation", NULL); } soap_response(soap, SOAP_HTML); sprintf(buf, "<html>value=%d</html>", val); soap_send(soap, buf); soap_end_send(soap); return SOAP_OK;}
- gsoap处理http post和http get
- 表单处理、HTTP协议和GET/POST
- httplib2处理http的get和post
- HTTP-GET和HTTP-POST- -
- HTTP-GET和HTTP-POST
- HTTP-GET 和 HTTP-POST
- HTTP-GET 和 HTTP-POST
- http post 和 get
- http get 和 post
- http post和get
- HTTP GET和POST区别
- perl http get和post
- HTTP GET 和 POST认知
- HTTP GET和POST区别
- HTTP的GET和POST
- iOS http get和post
- HTTP 中 Get 和Post
- HTTP Get 和Post区别
- Test - Driven Development By Example 测试驱动开发 (读书笔记)
- VC++动态链接库(DLL)编程深入浅出(zz)
- iOS7新特征汇总
- 搞IT也不能不懂“五险一金”啊
- 安卓之--动画效果的实现
- gsoap处理http post和http get
- cocos2d-x js binding tips 1 使用cocosbuilder导入jsb后无法响应触摸的问题
- python手记(7)
- oracle用户创建及权限设置
- 黑马程序员_毕向东_Java基础_DAY01学习笔记
- Android系统设计中存在设计模式分析
- window最大化后,里面的grid不跟着最大化,解决办法
- [Leetcode]Path Sum
- 位置无关码