iosobjective-creddit

"You broke Reddit" when submitting new story


I am making a Reddit app for the iPhone, and part of the app's functionality requires posting new stories (i.e. links or text) to Reddit.

When I attempt this, I make the following request and set the request's cookie based on a past login attempt:

http://www.reddit.com/api/submit/?uh=%@&text=TestofAPISubmitonapigee&kind=self&sr=redditdev&title=APISubmitTest&r=redditdev&api_type=json

(where %@ is replaced by the user modhash, something along the lines of aa4aaaa3aaaaaa88ea8b19639c389521a813d21cb3e5688dbf)

Upon submitting the request, however, I receive this response:

<html>
  <head>
    <title>reddit broke!</title>
  </head>
   <body>
    <div style="margin: auto; text-align: center">
      <p>
        <a href="/">
          <img border="0" src="http://www.redditstatic.com/youbrokeit1.png" alt="you broke reddit" />
        </a>
      </p>
      <p>
        I've made a huge mistake!
      </p>
  </body>
</html>

Or a variation on the above message. Any thoughts on what I'm doing wrong?


Solution

  • I figured it out. All you have to do is put the POST data in the HTTP body of the NSMutableURLRequest using [request setHTTPBody:@"NSString of the POST data"]; rather than the above, which is technically a GET request. I found this confusing, since this method worked for logging in to Reddit using the API. It turns out that you can login by GETting, but you must POST to share a new link.