【发布时间】:2014-09-22 23:49:11
【问题描述】:
HttpPost httpPost = new HttpPost("MyWebsiteURL");
try {
httpPost.setEntity(new StringEntity("https://www.googleapis.com/plus/v1/people/me?key="+token));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream is = httpEntity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
String json = sb.toString();
Log.i("JSON", json);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
【问题讨论】:
-
我认为我们不能使用 post 方法在 URL 中传递参数..
-
@Prag's 那么如何使用谷歌令牌与我的网站建立连接?
-
@Prag 很抱歉.. URL 类似于 Mywebsite/auth/auth2_login
-
使用 BasicNameValuePair 传递令牌
-
@Prag's 这是 BasicNameValuePair 的语法 --- 它有两个参数,我如何只传递令牌。 List
对 = new ArrayList (); pair.add(new BasicNameValuePair("key1", "value1")); post.setEntity(new UrlEncodedFormEntity(pairs));
标签: android http-post google-oauth access-token httpentity