My application needs to be able to upload video to Twitter. To initiate a chunked upload, the application needs to make a POST request like this:
The trouble I am having relates to the encoding of the forward slash character in the
media_type=video/mp4 parameter. My application is written in Scala and it uses the Spray.io HTTP client library for creating requests and parsing responses. We have our own implementation of OAuth 1.0a for signing the requests.
By experimenting with Twitter’s tools, it appears that Twitter requires the forward slash to be percent-encoded as
%2F in the HTTP request. In other words, it expects the request URL to be exactly this:
However, the Spray library will not allow us to encode the parameter string like this. If we specify the parameter value using a
/, then it remains a
/ when the request is sent. If we change the
%2F in the parameter value, then Spray thinks that the
% character itself needs to be percent encoded. Either way, we end up with a
401 Unauthorized response from Twitter.
First, I want to ask the Developer community if anyone else is using Scala and Spray and has found a way to work around this limitation in Spray? Is there some way to get Spray to encode the parameter string the way that Twitter requires? Or are we going to have to use some different HTTP client library to make this one REST request?
I would appreciate it if someone from Twitter could comment on this question: why does Twitter require that the forward slash be percent-encoded? I understand that the OAuth algorithm requires that character to be percent encoded when calculating the signature, but it seems to me that requiring the percent-encoding of that character on the HTTP request itself conflicts with RFC 3986.