Sam Stern
Sam Stern

Reputation: 25134

Java: Sending byte[] with other parameters in HTTP Post

I am working on a Java Client Library for the recently exposed unofficial Snapchat API. As an aside, the GitHub for my library so far is here: https://github.com/hatboysam/JavaSnap

I have most requests working fine, I can log in, download images, etc. I am using UniRest for all of those requests so far because I like the simplicity of the API.

I am trying to upload media following the format outlined here: http://gibsonsec.org/snapchat/fulldisclosure/#uploading-and-sending-snaps-phupload-phsend

I have no problem generating any of the fields. The data is a byte[] of AES-ECB encrypted data that I read from a file and ran through the specified encryption algorithm.

I have tried a few things:

If you look at the upload method in the Python library pysnap (init.py">https://github.com/martinp/pysnap/blob/master/pysnap/init.py) you can see that what I am trying to do has been done before very simply with Python's requests library. I can't figure out how to get the same behavior in Java.

Upvotes: 0

Views: 2067

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234847

My understanding is that you need to encode the byte[] data as a string using base-64 encoding. Try using javax.xml.bind.DatatypeConverter.printBase64Binary or a third-party library for base-64.

Converting to a string using String(byte[] bytes, String encoding) is completely different.

Upvotes: 3

Related Questions