有个项目需要向Google提供数据,Google指定使用proto传输;
经过几天的研究,可以使用数据结构的proto文件,通过protoc编译成java类,但是我通过类中writeTo方法写入到文件,通过HTTPS POST方式传递给Google时,总是报:HTTP/1.1 400 Bad Request 错误。
经过和Google支持人员的沟通,说我生成的proto文件有问题,如果是内容有问题,应该会报定义好的错误,报400错误应该是proto文件有问题。
所以我想问一下,java生成.proto文件该如何操作呢?我生成文件的代码如下:
UpdateUsersDataRequest.Builder updateUsersDataRequestBuilder = UpdateUsersDataRequest.newBuilder();
UserDataOperation.Builder userdataBuilder = UserDataOperation.newBuilder()
.setUserId("CAESEA1JoU33g1KZx6bRNobFr68")
.setUserListId(57543966)
.setTimeAddedToUserList(2132132132)
.setDataSourceId(1);
updateUsersDataRequestBuilder.addOps(userdataBuilder.build());
userdataBuilder = UserDataOperation.newBuilder()
.setUserId("CAESEA1eU2gPJxqEKtc_BnUMrJQ")
.setUserListId(57543966)
.setTimeAddedToUserList(2132132132)
.setDataSourceId(1);
updateUsersDataRequestBuilder.addOps(userdataBuilder.build());
UpdateUsersDataRequest updateUsersDataRequest = updateUsersDataRequestBuilder.build();
// System.out.println(updateUsersDataRequest);
// 写入到proto文件
String protoFile = "test2.proto";
FileOutputStream output = new FileOutputStream(protoFile);
updateUsersDataRequest.writeTo(output);
output.close();
The proto file refers to the definition file that defines the protocol protocol. This is the specific protocol data output. You should check whether the proto protocol file used to generate java classes is consistent with the protocol file specified by Google
Have you solved this problem?
We are also connecting with Google. Can you give us your contact information? I have already sent you a message on Weibo.