sar*_*ngj 5 twitter https android http httpsurlconnection
所以我目前正在编写一个 android 应用程序,它将使用 Twitter 的 1.1 Application-only-auth从特定用户获取推文,这需要一个 POST HTTP 请求来获取承载令牌。我设置了一个使用 anHttpsURLConnection来打开连接的方法,但是
conn.setDoOutput(true); 方法不起作用conn.doOutput 停留 falseGET。难道我做错了什么?
这个方法在 anAsyncTask的方法中调用doInBackground():
public String getRequestBearerToken(String endUrl) throws IOException {
String encodedCred = encodeKeys("API-key", "API-secret");
HttpsURLConnection connection = null;
try {
URL url = new URL(endUrl);
connection = (HttpsURLConnection) url.openConnection();
connection.setInstanceFollowRedirects(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
// POST request properties
connection.setRequestProperty("Host", "api.twitter.com");
connection.setRequestProperty("User-Agent", getResources()
.getString(R.string.app_name));
connection.setRequestProperty("Authorization", "Basic "
+ encodedCred);
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded;charset=UTF-8");
connection.setRequestProperty("Content-Length", "29");
connection.setUseCaches(false);
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
570 次 |
| 最近记录: |