I am not sure if I did something wrong or not,
but everytime when I submit a should-be-no-problem request to img.ly,
it returns 406 without any further information.
That response code wasn't documented and I cannot find anything from google,so I decided to figure that out.
First, I tried clients on my mac which uploads to img.ly:
Numbu uses the old API, boo.
Twitter for mac (no longer Tweetie for mac....) uses the old API too, but it treats the old API as the new one,
submitting OAuth Echo infos to http://img.ly/api/upload which doesn't make sense at all,
it should not work at all, but it dose.
So I am not going to follow it.
The last one is Twitterific, luckily it dose what I want.
It submits to http://img.ly/api/2/upload.xml which is what I am trying to do.
After comparing my failed request and Twitterific's success request, here are points that lead me to fail:
  • Content-Type: image/jpeg , I used ASIHttpRequest which uses¬†application/octet-stream as the default content-type, so the solution is
    [request setData:UIImageJPEGRepresentation(picture, 0.8) withFileName:@"filename.jpg" andContentType:@"image/jpeg" forKey:@"media"];
  • User-agent, this is super weird. Using "Maha 1.0 (iPhone Simulator; iPhone OS 4.2; en_US)" as the user agent, which is the default, makes me fail. But if I copy Twitterific's user agent "Twitterrific/4.0 CFNetwork/454.11.5 Darwin/10.6.0 (i386)", it works like a charm. So my solution is
    [request addRequestHeader:@"User-Agent" value:@"Maha/1.0 CFNetwork/454.11.5 Darwin/10.6.0 (i386)"];
And everything works now, tho I don't know what was the real problem.
Blog Logo

b123400


Published