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.
Related
How can I get POST request to work with an "https:" url?
In the following example when I set the URL to "https" instead of "http" the HttpURLConnection automatically makes my request a "GET" ?! while when it was a regular http request it was a POST...
URL url = new URL("*https:*//www.google.com");
// URL url = new URL("*http:*//www.google.com");
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();
}
enter image description here
Use HttpsURLConnection instead of HttpURLConnection
I have a problem with facebook.
In connection i have:
URL url = new URL("https://www.googleapis.com/oauth2/v1/userinfo?access_token="+ token);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
int sc = con.getResponseCode();
and I get:
java.net.UnknownHostException: Unable to resolve host "www.googleapis.com": No address associated with hostname
I have all permissions in manifest like:access_network and Internet.
I resolve my problem:
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setReadTimeout(10000 /* milliseconds */);
con.setConnectTimeout(15000 /* milliseconds */);
con.setRequestMethod("GET");
con.setDoInput(true);
// Starts the query
con.connect();
int sc = con.getResponseCode();
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?
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?
I am trying to hit this services but this gives me html reponse please help me where i am wrong
any help is really very help ful
HttpURLConnection connection;
java.net.URL u;
u = new java.net.URL("http://sdservices.iyogi.net/iyogi/webservicesnonrestv5/toolbarwebservices.asmx");
URLConnection uc = u.openConnection();
connection = (HttpURLConnection) uc;
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("SOAPAction", "http://sdservices.iyogi.net/SD/ToolbarService.svc/GetProductSettings?SubscriptionCode=W101982488");
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-type", "text/xml; charset=utf-8");
InputStream is = connection.getInputStream();
inputStreamToString(is);
gives HTML in response:(