我想发一个POST请求,以便获取“评论”列表。以下帖子请求是有问题的: http://www.reddit.com/dev/api#POST_api_morechildren
现在我有点困惑...... 首先:我是以JSON还是以HTML格式发送帖子请求? 第二:我得到的答案是HTML文档,但不正确。
这是我到目前为止构建POST请求的原因:
public static void moreCommentsPostRequest(MoreComment c, String postId)
throws IOException, JSONException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://www.reddit.com/api/morechildren");
httppost.setHeader("Accept", "application/json");
httppost.setHeader("Content-type", "application/json");
JSONStringer vm;
vm = new JSONStringer().object().key("api_type").value("json")
.key("children").value(childrenCSV).key("link_id")
.value(postId).endObject();
StringEntity httpPostEntity = new StringEntity(vm.toString());
httppost.setEntity(httpPostEntity);
// Execute and get the response.
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
try {
StringWriter writer = new StringWriter();
IOUtils.copy(instream, writer, "UTF-8");
String theString = writer.toString();
} finally {
instream.close();
}
}
}
我回复的回复:
03-11 01:55:45.140: I/running(20225): response: <!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
<head>
<title>reddit.com: forbidden (reddit.com)</title>
<meta name="keywords" content=" reddit, reddit.com, vote, comment, submit " />
<meta name="description" content="reddit: the front page of the internet" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=1024">
<link rel='icon' href="http://www.redditstatic.com/icon.png" sizes="256x256" type="image/png" />
<link rel='shortcut icon' href="http://www.redditstatic.com/favicon.ico" type="image/x-icon" />
<link rel='apple-touch-icon-precomposed' href="http://www.redditstatic.com/icon-touch.png" />
<link rel="stylesheet" type="text/css" href="http://www.redditstatic.com/reddit.tbeSemFBRCM.css" media="all">
<!--[if lt IE 7]>
<link rel="stylesheet" href="http://www.redditstatic.com/reddit-ie6-hax.nzvIdaFFlC8.css" type="text/css" />
<![endif]--><!--[if lt IE 8]>
<link rel="stylesheet" href="http://www.redditstatic.com/reddit-ie7-hax.372dzeWThpM.css" type="text/css" />
<![endif]--><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script><script type="text/javascript" src="http://www.redditstatic.com/reddit-init.en.TdpFk8-t9Z8.js"></script><!--[if lt IE 9]><script type="text/javascript" src="http://www.redditstatic.com/html5shiv.n0ysDxgy3AI.js"></script><![endif]--><script type="text/javascript" id="config">r.setup({"ajax_domain": "www.reddit.com", "server_time": 1394520945.0, "post_site": "", "clicktracker_url": "//pixel.redditmedia.com/click", "logged": false, "cur_domain": "reddit.com", "gold": false, "is_fake": true, "renderstyle": "html", "over_18": false, "vote_hash": "", "adtracker_url": "//pixel.redditmedia.com/pixel/of_doom.png", "uitracker_url": "//pixel.redditmedia.com/pixel/of_discovery.png", "fetch_trackers_url": "//tracker.redditmedia.com/fetch-trackers", "modhash": false, "store_visits": false, "send_logs": true, "https_endpoint": "https://ssl.reddit.com", "extension": "", "static_root": "http://www.redditstatic.com", "status_msg": {"fetching": "fetching title...", "loading": "loading...", "submitting": "submitting..."}, "debug": false})</script><script type="text/javascript">reddit.cur_site = "t5_6";</script>
<style type="text/css">/* Custom css: use this block to insert special translation-dependent css in the page header */</style>
</head>
<body class="" >
<div id="header" role="banner">
<a tabindex="1" href="#content" id="jumpToContent">jump to content</a>
<div id="sr-header-area">
<div class="width-clip">
<div class="dropdown srdrop " onclick="open_menu(this)" onmouseover="hover_open_menu(this)"><span class="selected title">my subreddits</span></div>
<div class="drop-choices srdrop ">
<a href="http://www.reddit.com/r/AdviceAnimals/" class="choice " >AdviceAnimals</a><a href="http://www.reddit.com/r/announcements/" class="choice " >announcements</a><a href="http://www.reddit.com/r/AskReddit/" class="choice " >AskReddit</a><a href="http://www.reddit.com/r/askscience/" class="choice " >askscience</a><a href="http://www.reddit.com/r/aww/" class="choice " >aww</a><a href="http://www.reddit.com/r/bestof/" class="choice " >bestof</a><a href="http://www.reddit.com/r/blog/" class="choice " >blog</a><a href="http://www.reddit.com/r/books/" class="choice " >books</a><a href="http://www.reddit.com/r/EarthPorn/" class="choice " >EarthPorn</a><a href="http://www.reddit.com/r/explainlikeimfive/" class="choice " >explainlikeimfive</a><a href="http://www.reddit.com/r/funny/" class="choice " >funny</a><a href="http://www.reddit.com/r/gaming/" class="choice " >gaming</a><a href="http://www.reddit.com/r/gifs/" class="choice " >gifs</a><a href="http://www.reddit.com/r/IAmA/" class="choice " >IAmA</a><a href="http://www.reddit.com/r/movies/" class="choice " >movies</a><a href="http://www.reddit.com/r/Music/" class="choice " >Music</a><a href="http://www.reddit.com/r/news/" class="choice " >news</a><a href="http://www.reddit.com/r/pics/" class="choice " >pics</a><a href="