I am working on a Twitter API for Rust and am running into issues with passing arguments to my GET request. The code I'm using for the request is given below. data_body
is something like "screen_name=a_user" and the authorization header is the OAuth authorization required by Twitter (this isn't the issue as it's working with all my other requests).
let mut res = client.get("http://httpbin.org/get")
.body(&data_body[..])
.header(Authorization(authorization_header))
.header(ContentType::form_url_encoded())
.send().unwrap();
I started sending this to httpbin.org so I could see the raw request. What I'm getting back is shown below.
{
"args": {},
"headers": {
"Authorization": "OAuth oauth_consumer_key=\"\", oauth_nonce=\"RH9vZYMCbAtfQAuVh44fhlyGQfQqBCPq\", oauth_signature=\"dTbOyaURct0auVlC%2B8Y7vDFpus0%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1452648640\", oauth_token=\"\", oauth_version=\"1.0\"",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org"
},
"origin": "0.0.0.0",
"url": "http://httpbin.org/get"
}
The curl request given by the Twitter api docs have a data portion for the GET request below (I've replaced my keys with empty strings). I can confirm this works for the GET.
curl --get 'https://api.twitter.com/1.1/users/show.json' --data 'screen_name=twitterdev' --header 'Authorization: OAuth oauth_consumer_key="", oauth_nonce="6a37886cb38b2f5e12dee8fd47aa097c", oauth_signature="zhXDA5JbKRmw2xbJcEqK9sxuu5E%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1452647580", oauth_token="", oauth_version="1.0"' --verbose
I've tried a bunch of different ContentType
s from the Hyper API but can't get the args section of the HTTP request populated. I think that's the issue, but I don't have a lot of experience with HTTP so I could very well be wrong. Ultimately the request is returning a 403 (Unauthorized) which is triggered by the missing args. I know my OAuth header is being generated correctly because it's working on all the POST requests and when I copy over the nonce and timestamp from the curl command I get from the Twitter API the signature matches.