如何从客户端传递gsoap C ++中的头文件中的非XML数据? [英] How to pass non XML data in header in gsoap C++ from client?
问题描述
我正在使用gsoap c ++库来进行java web服务调用。
我可以通过调用json_call来传递json文件,但我想添加头信息。为此,我将struct SOAP_ENV__Header修改为:
struct ns3__Header
{
char * username;
char *密码;
};
struct SOAP_ENV__Header
{
#ifdef WITH_NOEMPTYSTRUCT
char dummy;
#endif
struct ns3__Header * ns3__MyHeader;
};
现在我可以在标题中添加值,但是我的问题是它们以xml格式添加到标题中。但我只想标记:值格式。如何实现?
当我传递一个标题时,它看起来像:
当我传递一个标题时,它看起来像: br $> b $ b
<?xml version =1.0encoding =UTF-8?> < username id =_ 300> < NS3:myheader>
in soap_out_SOAP_ENV__Header
{
add:
{
i:10,
j:20,
}
}
但它应该看起来像:(标题不应该是服务器想要的xml - )
用户名:xyz
密码:abcd
...
...
{
添加:
{
i:10,
j:20,
< br $>
}
}
我的尝试:
i我不知道如何只用纯文本标题而不用xml
I am using gsoap c++ library to make a java web service call.
I can pass a json file by calling json_call, but i want to add header information. For that i modified the struct SOAP_ENV__Header as:
struct ns3__Header
{
char *username;
char* password;
};
struct SOAP_ENV__Header
{
#ifdef WITH_NOEMPTYSTRUCT
char dummy;
#endif
struct ns3__Header *ns3__MyHeader;
};
Now i can add values in header, but my problem is they are getting added in xml format to the header. But I want just tag:value format. How to achieve that?
When I pass a header, it looks like:
When I pass a header, it looks like:
<?xml version="1.0" encoding="UTF-8"?> <username id="_300"> <ns3:myheader>
in soap_out_SOAP_ENV__Header
{
"add":
{
"i": 10,
"j": 20,
}
}
But it should look like: (header should not be in xml as server wants in this way -)
username:xyz
password:abcd
...
...
{
"add":
{
"i": 10,
"j": 20,
}
}
What I have tried:
i am not sure how to have header only with plain text and not with xml
推荐答案
终于找到了一种方法使用gsoap时在休息呼叫中发送标题信息
Finally found a way which works to send header info in rest call while using gsoap
#include "json.h"
#include <string.h>
#include "jsonStub.h"
struct Namespace namespaces[] = { {NULL, NULL} };
int main()
{
struct soap *ctx = soap_new1(SOAP_XML_NOTYPE);
soap_init(ctx);
struct value *request = new_value(ctx);
struct value response;
ctx->sendfd = 1;
ctx->http_extra_header = "userName:abcd\r\npassword:xyz";
*string_of(value_at(value_at(request, "add"), "i")) = "10";
*string_of(value_at(value_at(request, "add"), "j")) = "20";
json_write(ctx, request);
printf("\n");
if (json_call(ctx, "endpoint",request, &response))
{
printf( "json call failed " );
soap_print_fault(ctx, stderr);
printf("\n%d", ctx->error);
printf("\n1: SOAP faultcode = %s\n", *soap_faultcode(ctx));
printf("2: SOAP faultstring = %s\n", *soap_faultstring(ctx));
printf("3: SOAP faultdetail = %s\n\n", *soap_faultdetail(ctx));
soap_print_fault_location(ctx, stderr);
}
else
{
printf("Success !!!");
json_write(ctx, &response);
}
soap_destroy(ctx);
soap_end(ctx);
soap_free(ctx);
return 0;
}
这篇关于如何从客户端传递gsoap C ++中的头文件中的非XML数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!