post - Java server cannot parseFrom protobuf byte[] -
i utilize libcurl c++ client in order submit post info java server. reason, post info (protobuf serializetostring) cannot parsed on server side.
here client side part:
string str; protobufmessage.serializetostring(&str); curl_easy_setopt(m_curl_handle, curlopt_postfields, str); curl_easy_setopt(m_curl_handle, curlopt_postfieldsize, str.size());
and here java code on server:
@produces(mediatype.application_octet_stream) @consumes(mediatype.application_octet_stream) public @responsebody byte[] updatestatus( @requestbody byte[] message) { seek { protobufmessage pbmessage = protobufmessage.parsefrom(message); ... }
when convert message string, next value - "%c3%b4%c3%ba%29%00%00%00%00%00%c3%bd%c3%bd%c3%bd%c3%bd%c2%ab%c2%ab%c2%ab%c2%ab%c2%ab%c2%ab="
however, client sending next value - "\b\x1\x1a\xe\n\x5hello\x12\x5world"
i believe somehow related encoding of transmitted bytes, how can command it?
also, here exception i'm getting on server side, while parsing message - com.google.protobuf.invalidprotocolbufferexception: protocol message end-group tag did not match expected tag.
according this documentation, parameter curlopt_postfields
needs char*
. you're passing std::string
. don't compile error because curl_easy_setopt
c-style vararg function, has no type checking.
change line to:
curl_easy_setopt(m_curl_handle, curlopt_postfields, str.data());
an additional possible problem here libcurl send request content-type: application/x-www-form-urlencoded
. many web servers recognize type , effort parse form data. should override content-type
application/x-protobuf
or maybe application/octet-stream
(which means "byte blob") avoid problems.
java post encoding protocol-buffers libcurl
No comments:
Post a Comment