这是我的网址帖子:
String urlParameters = "&consumer_key="+AppSession.getPocketConsumerKey()+"&client_secret="+AppSession.getPocketRedirectUri();
String request = "https://getpocket.com/v3/oauth/request";
URL url;
try {
url = new URL(request);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("X-Accept","application/x-www-form-urlencoded");
connection.setUseCaches (false);
connection.connect();
DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
wr.writeBytes(urlParameters);
Log.d("urlparmas",urlParameters);
wr.flush();
wr.close();
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
Log.d( "response",response.toString());
} catch (Exception e) {
e.printStackTrace();
}
我的重定向 Uri:MyApp://callback
<activity android:name="com.app.account.Register" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="MyApp" android:host="callback"/>
</intent-filter>
</activity>
所以,我只是没有从回调 url 得到任何回复。想知道我在代码中哪里出错了。
编辑:
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
Log.d( "response",response.toString());
这会产生错误。