我在获取视频的直接链接时遇到问题。我想在我的 WebView/VideoView 中播放它。如何发送 POST 请求并通过来自网站的直接链接接收答案,该链接对此类内容进行解码:
videotools.12pings.net
有没有办法做到这一点?
示例:将链接放在网站表单中 - 然后单击按钮 - 按钮下方的直接链接已准备好
我在获取视频的直接链接时遇到问题。我想在我的 WebView/VideoView 中播放它。如何发送 POST 请求并通过来自网站的直接链接接收答案,该链接对此类内容进行解码:
videotools.12pings.net
有没有办法做到这一点?
示例:将链接放在网站表单中 - 然后单击按钮 - 按钮下方的直接链接已准备好
final HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is
// established.
HttpConnectionParams.setConnectionTimeout(httpParameters, 7000);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
HttpConnectionParams.setSoTimeout(httpParameters, 10000);
HttpClient client = new DefaultHttpClient(httpParameters);
HttpResponse response = client.execute(new HttpGet(path));
HttpEntity entity = response.getEntity();
InputStream imageContentInputStream = entity.getContent();
path 是包含您的 URL 的变量
我希望这会对你有所帮助.. *你需要得到 httpcomponents-client-4.1.zip 和 apache-mime4j-0.6.1-bin.zip
从 httpcomponents-client-4.1.zip 的 lib 文件夹中添加 apache-mime4j-0.6.1-bin.zip 和 httpclient-4.1.jar httpcore-4.1.jar httpmime-4.1.jar - 查看更多信息:http://blog .tacticalnuclearstrike.com/2010/01/using-multipartentity-in-android-applications/#stash.N7qT8apH.dpuf *
try {
MultipartEntity multipart = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
FormBodyPart office = new FormBodyPart("office",
new StringBody(getOffice));
multipart.addPart(office);
String imageCount = Integer.toString(drawableList.size());
System.out.println("ImageCount : " + imageCount);
FormBodyPart imgNo = new FormBodyPart("imgNo", new StringBody(
imageCount));
multipart.addPart(imgNo);
} catch (Exception e) {
// TODO: handle exception
}
try {
System.out.println("result : " + multipart.getContentLength());
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(CommunicatorUrl.ADD_INCIDENT);
httppost.setEntity(multipart);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
// print responce
outPut = EntityUtils.toString(entity);
} catch (Exception e) {
Log.e("log_tag ******",
"Error in http connection " + e.toString());
}
基本上,这个 MultipartEntity 对于使用 post 方法将多个图像和数据发送到服务器很有用
String paramUsername = "username";
String paramPassword = "password";
System.out.println("*** doInBackground ** paramUsername " + paramUsername + "
paramPassword :" + paramPassword);
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://www.xxxxxxxxxxxxxx.php");
BasicNameValuePair usernameBasicNameValuePair = new BasicNameValuePair("ParamUsername", paramUsername);
BasicNameValuePair passwordBasicNameValuePAir = new BasicNameValuePair("paramPassword", paramPassword);
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
nameValuePairList.add(usernameBasicNameValuePair);
nameValuePairList.add(passwordBasicNameValuePAir);
try {
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(nameValuePairList);
httpPost.setEntity(urlEncodedFormEntity);
try {
HttpResponse httpResponse = httpClient.execute(httpPost);
InputStream inputStream = httpResponse.getEntity().getContent();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder stringBuilder = new StringBuilder();
String bufferedStrChunk = null;
while((bufferedStrChunk = bufferedReader.readLine()) != null){
stringBuilder.append(bufferedStrChunk);
}
return stringBuilder.toString();
} catch (ClientProtocolException cpe) {
System.out.println("First Exception caz of HttpResponese :" + cpe);
cpe.printStackTrace();
} catch (IOException ioe) {
System.out.println("Second Exception caz of HttpResponse :" + ioe);
ioe.printStackTrace();
}
} catch (UnsupportedEncodingException uee) {
System.out.println("An Exception given because of UrlEncodedFormEntity argument :" + uee);
uee.printStackTrace();
}