Trying to download traineddata files(Tesseract) - android

i'm trying to download this file: tesseract-ocr-3.02.eng.tar.gz on android with the commands:
HttpURLConnection urlConnection = null;
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setAllowUserInteraction(false);
urlConnection.setInstanceFollowRedirects(true);
urlConnection.setRequestMethod("GET");
urlConnection.connect();
from this url = "https://tesseract-ocr.googlecode.com/files/tesseract-ocr-3.02.eng.tar.gz"; and it is not working. It is throwing an UnknownHostExeception and the error is coming from the last command urlConnection.connect();
What can i do for fixing it and download the file?

Related

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?

video url Http error 405 can't download

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", "");

android urlconnection forces ssl

I am trying to connect to a server on port 8080 but AndroidHttpClient is forcing everything not on 8080 to use SSL. The offending code
URL url = new URL("http", "google.com", 8080, "");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setRequestProperty("Accept", "*/*");
urlConnection.connect();
and this from Charles log.
note the URL field is using "https://"
now when I change the port to 80:
URL url = new URL("http", "google.com", 80, "");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setRequestProperty("Accept", "*/*");
urlConnection.connect();
everything works fine:
I have no idea why it forces it to SSL when not on port 80. I had a similar issue with AndroidHttClient as well as DefaultHttpClient. Seems to be an issue with Android.

Android2.2 url connect exception

I have the following code for url connect, which throws an exception but the exception object is empty. how to connect to a url without any exception in android 2.2
HttpURLConnection urlConnection= null;
URL url = null;
try
{
url = new URL(urlString.toString());
urlConnection=(HttpURLConnection)url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();
}
catch(Exception ex)
{//ex is empty here}
I think a get-request does not like when output is enabled. In this case you should
not set:
urlConnection.setDoOutput(true);

Http get request in Android

I need help with sending http get request. Like this:
URL connectURL;
connectURL = new URL(address);
HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection();
// do some setup
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("GET");
// connect and flush the request out
conn.connect();
conn.getOutputStream().flush();
// now fetch the results
String response = getResponse(conn);
et.setText(response);
I searched the web but any method I try, the code fails at 'conn.connect();'. Any clues?
Very hard to tell without the actual error message. Random thought: did you add the internet permission to you manifest?
<uses-permission android:name="android.permission.INTERNET"/>
If you want some demo code then try following:
URL url = new URL("url.com");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);
} finally {
urlConnection.disconnect();
}
and this:
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(0);
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
writeStream(out);
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);
} finally {
urlConnection.disconnect();
}
Hope this helps.

Categories

Resources