https://player.vimeo.com/video/136004191/config尝试从 vimeo 获取真实 URL,而我收到错误:
response code:405
07-26 11:42:46.236 22054-22183/com.sample.samplevideoview W/System.err: java.io.FileNotFoundException: https://player.vimeo.com/video/136004191/config
07-26 11:42:46.236 22054-22183/com.sample.samplevideoview W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:238)
07-26 11:42:46.236 22054-22183/com.sample.samplevideoview W/System.err: at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
07-26 11:42:46.236 22054-22183/com.sample.samplevideoview W/System.err: at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err: at com.sample.samplevideoview.AsyncHttpClient$AsyncDataRequestHideDialog.doInBackground(AsyncHttpClient.java:353)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err: at com.sample.samplevideoview.AsyncHttpClient$AsyncDataRequestHideDialog.doInBackground(AsyncHttpClient.java:287)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err: at java.lang.Thread.run(Thread.java:818)
07-26 11:42:46.281 22054-22054/com.sample.samplevideoview E/MainActivity: Must implement the interface java.lang.NullPointerException: Attempt to invoke virtual method 'com.sample.samplevideoview.Request com.sample.samplevideoview.VimeoResponse.getRequest()' on a null object reference
这是代码:
private void getRealUrl(String videoId)
{
AsyncHttpClient mAsyncHttpClient = new AsyncHttpClient();
HashMap<String, String> params = new HashMap<>();
String url = "https://player.vimeo.com/video/" + videoId + "/config";
mAsyncHttpClient.postWithStringData(MainActivity.this, TAG,
url, StringConstants.METHOD_GET, params,false,
new AsyncHttpClient.AsyncHttpResponseCallBack() {
@Override
public void onResponse(String response) {
Gson gson = new GsonBuilder().create();
VimeoResponse movie = gson.fromJson(response, VimeoResponse.class);
}
}
);
}
public class AsyncHttpClient {
public interface AsyncHttpResponseCallBack {
void onResponse(String response);
}
private Vector<Object> params;
private static final String UTF_ENCODING = "UTF-8";
private static final int CONTEXT_INDEX = 0;
private static final int TAG_INDEX = 1;
private static final int URL_INDEX = 2;
private static final int PARAMS_STRING_INDEX = 3;
private static final int RESPONSE_CALLBACK_INDEX = 4;
private static final int REQUEST_METHOD_INDEX = 5;
private static final int SHOW_PROGRESS_DIALOG_INDEX = 6;
public void postWithStringData(Context context, String TAG, String url, String method,
HashMap<String, String> hashMapParams, boolean showDialog,
AsyncHttpResponseCallBack asyncHttpResponseCallBack) {
if (Utilities.isConnected(context)) {
try {
params = new Vector<>();
params.insertElementAt(context, CONTEXT_INDEX);
params.insertElementAt(TAG, TAG_INDEX);
params.insertElementAt(url, URL_INDEX);
params.insertElementAt(getPostDataString(hashMapParams), PARAMS_STRING_INDEX);
params.insertElementAt(asyncHttpResponseCallBack, RESPONSE_CALLBACK_INDEX);
params.insertElementAt(method, REQUEST_METHOD_INDEX);
new AsyncDataRequestHideDialog(context).execute(params);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
private class AsyncDataRequestHideDialog extends AsyncTask<Vector<Object>, Void, String> {
AlertDialog mAlert;
String TAG, url;
String paramsString;
AsyncHttpResponseCallBack asyncHttpResponseCallBack;
Context context;
String method;
public AsyncDataRequestHideDialog(Context context) {
// TODO Auto-generated constructor stub
this.context = context;
}
@Override
protected String doInBackground(Vector<Object>... params) {
Vector<Object> requestParams = params[0];
TAG = (String) requestParams.get(TAG_INDEX);
url = (String) requestParams.get(URL_INDEX);
paramsString = (String) requestParams.get(PARAMS_STRING_INDEX);
asyncHttpResponseCallBack = (AsyncHttpResponseCallBack) requestParams.get(RESPONSE_CALLBACK_INDEX);
method = (String) requestParams.get(REQUEST_METHOD_INDEX);
String result = "";
URL requestURL;
StringBuffer response;
try {
requestURL = new URL(url);
HttpURLConnection conn = (HttpURLConnection) requestURL.openConnection();
conn.setReadTimeout(StringConstants.READ_TIMEOUT);
conn.setConnectTimeout(StringConstants.CONNECTION_TIMEOUT);
conn.setRequestMethod(method);
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, UTF_ENCODING));
writer.write(paramsString);
writer.flush();
writer.close();
os.close();
String line;
response = new StringBuffer();
Log.d(TAG,"response code:"+conn.getResponseCode());
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = br.readLine()) != null) {
response.append(line);
}
result = response.toString();
} catch (SocketTimeoutException e1) {
e1.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
Log.d(TAG, result);
return result;
}
}
// Overriding onPreExecute to initialize and show progress dialog
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
// If result is not null
if (result != null) {
try {
// Making a log just to make sure of data.
Log.e(TAG, result);
asyncHttpResponseCallBack.onResponse(result);
} catch (Exception e) {
Log.e(TAG, "Must implement the interface " + e.toString());
}
} else {
mAlert = Utilities.createAlertDialog(context, "Error",
StringConstants.DATA_ERROR);
}
}
}
当我得到响应代码 405 时?什么问题?移动和桌面浏览器中的相同 url 响应我。