问题描述
gsoap-master拥有httpgettest.c文件来测试http获取请求并打印响应数据。
我想在同一应用程序中打印响应标头的特定键值。
我已搜索并找到以下解决方案 gSoap - parse custom http header from request
但是它不起作用。下面是修改后的代码
#include "soapH.h"
#include "httpget.h"
int my_parsehdr(struct soap *soap,const char *key,const char *val);
int main(int argc,char **argv)
{ struct soap soap;
char *body;
if (argc < 2)
{ fprintf(stderr,"Usage: httpgettest URL\n");
exit(0);
}
soap_init(&soap);
soap_register_plugin(&soap,http_get); /* register plugin */
if (soap_http_get_connect(&soap,argv[1],NULL)
|| soap_begin_recv(&soap))
{ soap_print_fault(&soap,stderr);
exit(1);
}
if (soap.http_content)
printf("HTTP Content Type: %s\n",soap.http_content);
body = soap_http_get_body(&soap,NULL);
soap_end_recv(&soap);
if (body)
printf("HTTP Body:\n%s\n",body);
soap.user = (void*)soap.fparsehdr; // to call fparsehdr() in our callback
soap.fparsehdr = my_parsehdr;
char *key = "Host";
char *value = "";
int return_val = soap.fparsehdr(&soap,key,value);
printf("HTTP fparsehdr return val: %d \n",return_val);
printf("HTTP header Key:%s\n",key);
printf("HTTP header value:%s\n",value);
soap_end(&soap);
soap_done(&soap);
return 0;
}
SOAP_NMAC struct Namespace namespaces[] =
{
{NULL,NULL,NULL}
};
typedef int(*PARSEFUNC)(struct soap*,const char*,const char*);
int my_parsehdr(struct soap *soap,const char *val)
{
printf ("\n\n Inside call back \n\n");
// check key (non-NULL) and use val (non-NULL)
return ((PARSEFUNC)(soap->user))(soap,val);
}
这里我使用了fparsehdr回调函数来解析标题键
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)