C++ gSoap-从客户端应用程序httpgettest.c中的响应解析自定义http头
gsoap主机有httpgettest.c文件来测试http get请求并打印响应数据 我想在同一个应用程序中打印响应头的特定键值 我已搜索并找到以下解决方案 但它不起作用。下面是修改后的代码C++ gSoap-从客户端应用程序httpgettest.c中的响应解析自定义http头,c++,c,http-headers,soap-client,gsoap,C++,C,Http Headers,Soap Client,Gsoap,gsoap主机有httpgettest.c文件来测试http get请求并打印响应数据 我想在同一个应用程序中打印响应头的特定键值 我已搜索并找到以下解决方案 但它不起作用。下面是修改后的代码 #include "soapH.h" #include "httpget.h" int my_parsehdr(struct soap *soap, const char *key, const char *val); int main(int argc, c
#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, NULL}
};
typedef int(*PARSEFUNC)(struct soap*, const char*, const char*);
int my_parsehdr(struct soap *soap, const char *key, 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, key, val);
}
#包括“soapH.h”
#包括“httpget.h”
int my_parsehdr(结构soap*soap,常量char*key,常量char*val);
int main(int argc,字符**argv)
{struct soap;
字符*体;
如果(argc<2)
{fprintf(stderr,“用法:httpgettesturl\n”);
出口(0);
}
soap_init(&soap);
soap_register_插件(&soap,http_get);/*注册插件*/
if(soap\u http\u get\u connect(&soap,argv[1],NULL)
||soap\u begin\u recv(&soap))
{soap_print_fault(&soap,stderr);
出口(1);
}
if(soap.http\u内容)
printf(“HTTP内容类型:%s\n”,soap.HTTP\u内容);
body=soap\u http\u get\u body(&soap,NULL);
soap\u end\u recv(&soap);
如果(正文)
printf(“HTTP正文:\n%s\n”,正文);
soap.user=(void*)soap.fparsehdr;//在回调中调用fparsehdr()
soap.fparsehdr=my_parsehdr;
char*key=“主机”;
字符*值=”;
int return_val=soap.fparsehdr(&soap,key,value);
printf(“HTTP fparsehdr返回值:%d\n”,返回值);
printf(“HTTP头密钥:%s\n”,密钥);
printf(“HTTP头值:%s\n”,值);
肥皂端(和肥皂);
soap_done(&soap);
返回0;
}
SOAP\u NMAC结构命名空间[]=
{
{NULL,NULL,NULL,NULL}
};
typedef int(*PARSEFUNC)(结构soap*,常量字符*,常量字符*);
int my_parsehdr(结构soap*soap,常量char*key,常量char*val)
{
printf(“\n\n内部回调\n\n”);
//检查键(非空)并使用val(非空)
返回((PARSEFUNC)(soap->user))(soap,key,val);
}
这里我使用了fparsehdr回调函数来解析头键