video url Http error 405 can't download - android

I have an online video url, I can use vitamio video player play it online, but once I use android HttpUrlConnection download, I failed and received http 405 error.Can anyone give me some help?
HttpURLConnection conn = null;
int totalSize = 0;
conn = (HttpURLConnection) new URL(url).openConnection();
conn.setConnectTimeout(10 * 1000);
conn.setRequestMethod("GET");
conn.connect();
totalSize = conn.getContentLength();
[1]:http://219.238.10.102/videos/v0/20140303/43/4c/69/cd1e834831bfafcdef321e0037050f45.mp4?key=9070001543d27aea&path=/data1/www&m=DC96181615C9D859EB81DA194598DF31A8A3F8DBD9CC94AB612C1489A6574E08E898F5CE76C1BA00DEEE348748C27D82DCCEF4183D058C45DD96616D9D87753F263ADF611C41D0531BA1BDCFD7DE9B16&uuid=4cc6f4b2f1d7b13fa4fd9b4233e0094fc016327ac6ddc126dc54d6f359bcca4b
the url is [the url of a video][1]
I put the url on http://web-sniffer.net/, it displayed right length which is 71917427.

This problem was finally solved by add userAgent:
conn.setRequestProperty("User-agent", "");

Related

Response 301 Moved Permanently

I used to get the following response to php request
Response:
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
my code:
URL url = new URL("http://myappdemo.com/payumoney/payUmoneyHashGenerator.php");
// get the payuConfig first
String postParam = postParams[0];
byte[] postParamsByte = postParam.getBytes("UTF-8");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setInstanceFollowRedirects(false);
conn.setRequestProperty("Content-Length",
String.valueOf(postParamsByte.length));
conn.setDoOutput(true);
conn.getOutputStream().write(postParamsByte);
InputStream responseInputStream = conn.getInputStream();
StringBuffer responseStringBuffer = new StringBuffer();
byte[] byteContainer = new byte[1024];
for (int i; (i = responseInputStream.read(byteContainer)) != -1; ) {
responseStringBuffer.append(new String(byteContainer, 0, i));
}
Log.e("tag", "doInBackground: "+ responseStringBuffer.toString());
also tried with volley reponse was
BasicNetwork.performRequest: Unexpected response code 301 for
http://myappdemo.com/payumoney/payUmoneyHashGenerator.php
.
Please help me.
Thanks in Advance.
301 Moved Permanently is used for permanent URL redirection.Current links using the URL that the response is received for should be updated. try to use https:// in your link
use URL url = new URL("https://myappdemo.com/payumoney/payUmoneyHashGenerator.php");

Error 403 forbidden - using HttpURLConnection - authorization issue?

I have responseCode = 403.
Do you see any issue in the code below?
I tried every flag in the Base64.encode.
My site woks perfectly fine: once I login in manually from http passing my username/passwd, I'm able to retrieve the JSON data using https.
Do you think I'm correct in suspecting an authorization issue?
URL object = new URL("https://aaaaaa.bb/api/?format=json" );
HttpURLConnection connection = (HttpURLConnection) object.openConnection();
connection.setReadTimeout(60 * 1000);
connection.setConnectTimeout(60 * 1000);
connection.setRequestMethod("GET");
String authorization="xxxxxx#gmail.com:yyyyyy";
String encodedAuth="Basic "+ Base64.encode(authorization.getBytes(), Base64.DEFAULT);
connection.setRequestProperty("Authorization", encodedAuth);
connection.connect();
int responseCode = connection.getResponseCode();
Can you try by setting the content type:
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

Deleting file from Parse.com usung REST API in Android

Why can't I delete a file from parse.com? Here is my method.
URL url = new URL("https://api.parse.com/1/files/"+ parseFileName);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty ("X-Parse-Master-Key", Sett.PARSE_MASTER_KEY);
conn.setRequestProperty ("X-Parse-Application-Id", Sett.PARSE_APP_ID);
conn.setRequestProperty ("X-Parse-REST-API-Key", Sett.PARSE_REST_KEY);
conn.setRequestProperty ("Content-Type", "application/json");
conn.setRequestMethod("DELETE");
String responseStr = conn.getResponseMessage();
String responseCode = String.valueOf(conn.getResponseCode());
Result = 200 OK, but the file is still available for download. Also, I tried to send a request through the control panel from Parse.com. Result was null
This is a link to file I triying to delete http://files.parsetfss.com/5592cbfd-6fd4-41ca-8a82-dd90ebcd6541/tfss-410de5c1-bbac-4772-8be5-45b4f55d47fd-1450985755273

getContentLength return -1 when i try to download zip file

i try to download zip file from server and show progressBar, but i get conexion.getContentLength()=-1. That's why i can't show progress dialog, the downloading works fine. My code is below:
URLConnection conection = fileUrl.openConnection();
conection.connect();
int lenghtOfFile = conection.getContentLength();
Try HttpURLConnection instead of URLConnection and set setChunkedStreamingMode(100);
HttpURLConnection urlConnection = (HttpURLConnection) fileUrl.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(100);
urlConnection.connect();
int lenghtOfFile = urlConnection.getContentLength();
but I get -1
It is the expected behaviour, when the Content-Length header field of the response is not set. It is backend-side issue, not client side. As workaround you can display an indeterminate ProgressBar (the spinning one) instead of a determinate one

url.openConnection() does not open the connection to the server

I'm going to use HttpUrlConnection for calling a WebAPI. I simply call url.OpenConnectionMethod() to open the connection, but it doesn't work. Both allowUserInteraction and client.connected values of HtpUrlConnection instance are false.
URL url = new URL("http://myserver/service/api/ads/getads");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
any help would be appreciated.
Try this:
URL url = new URL("http://yourserver/x/y/z");
URLConnection urlConnection = url.openConnection();
if this doesn't work can I see any exceptions?

Categories

Resources