问题
I'm attempting to use the reddit API to make posts, but the server is returning 500 errors.
For example, I tried posting to this URL with my cookie set:
http://www.reddit.com/api/submit?title=testtitle&sr=compsci&uh=<modhash_goes_here>&text=testtext&kind=self
And my Chrome Dev Tools prints the following error:
POST <my long URL goes here> 500 (Internal Server Error)
I read somewhere on StackOverflow that you need both the modhash and the cookie, so that's what I'm using. I tried without the modhash, and I tried with the superfluous "r=subreddit" parameter listed on Apigee. Neither helped.
Why would I be getting a 500 error?
回答1:
You're not supposed to POST data in the URL; you set the data in the POST object, and the POST that.... Which makes sense, because you POST things like passwords. For example (using jQuery):
$.post('http://www.reddit.com/api/vote',
{
'id' : 't3_' + id,
'dir': dir,
'uh' : mod_hash
},
function(data) {
var err = false;
for (var i in data) {
if (data.hasOwnProperty(i)) {
err = true;
break;
}
}
// No error!
callback(err);
});
URLs just happen to work for some reddit API calls because they implemented them on GET in addition to POST.
来源:https://stackoverflow.com/questions/11301342/reddit-submit-api-500-error