Error with facebook connections in android - android

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();

Related

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.

Android: Internet connection cannot be established on my app with some devices

ich have written an app for android which has to download data from a website. All in all it works pretty well but i heard from some users that they the internet connection doesn't work when they use internet access via mobile internet. With the WLAN there are no problems and on my mobile phone it even works with mobile internet. I already ensured myself that the users who has got these problems do have internet access on other apps with their mobile internet...
Here is the source code, where I establish the connection.
String urlString = "http://google.com";
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("GET");
conn.setDoInput(true);
// Starts the query
conn.connect();
InputStream stream = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "ISO-8859-"));
String line = "";
while((line = reader.readLine()) != null){
line //do sthg with line
}
I hope that i gave enough information to you guys the help me to solve that problem
Regards
Maybe you could delete those
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);

SOAP Authentication Android

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:(

Works with Android 2.2 but not Android 2.3

i make an app which accept xml data, but when i send query for this resource , looks that there is no connection . I added android internet permissions and have net in browser but in my app there isn't any connection.
this is the code
protected String sendRequest(String urlAdr,ArrayList postVars){
String data=extractPairValuesToString(postVars);
urlAdr+=data; //send all variables in the url not from request properties
String xmlResponse=null;
HttpURLConnection con = null;
URL url;
try {
url = new URL(urlAdr);
con = (HttpURLConnection) url.openConnection();
//con.setReadTimeout(10000 /* milliseconds */);
//con.setConnectTimeout(15000 /* milliseconds */);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Content-Length", ""+Integer.toString(data.getBytes().length));
con.setDoInput(true);
con.setDoOutput(true);
}catch (IOException e) {
setErrorStatus(e.getMessage());
}
}
More times than not, the manifest is missing:
<uses-permission android:name="android.permission.INTERNET"/>
See here:
http://developer.android.com/resources/tutorials/views/hello-webview.html

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