Я пытаюсь подключиться к серверу из моего приложения, используя следующий код:
public void buildGamesList(View view){
String url = "http://somedomain.eu/blabla";
String response = "...";
try {
HttpGet getRequest = new HttpGet(url);
HttpClient client = new DefaultHttpClient();
HttpResponse resp = client.execute(getRequest);
response = responseToString(resp);
} catch (ClientProtocolException e1) {
System.out.println("ClientProtocolException: " + e1.toString());
} catch (IOException e2) {
System.out.println("IOException: " + e2.toString());
}
System.out.println("Response: " + response);
}
Этот метод вызывается при нажатии кнопки изображения, определенной как
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:weightSum="1">
<ImageButton android:src="@drawable/logo"
android:id="@+id/logoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:layout_gravity="center"
android:onClick="buildGamesList"></ImageButton>
</LinearLayout>
и проблема в том, что если я пишу URL, как указано выше (с ведущим http://), я получаю UnknowHostException, и если я пропускаю ведущий http: // я получаю java.lang.IllegalStateException: целевой хост не может быть нулевым или заданным в параметрах.
Может ли кто-нибудь помочь мне понять это?
Часть файла манифеста:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jef.android"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<permission android:name="android.permission.INTERNET"></permission>
<uses_permission android:name="android.permission.INTERNET"></uses_permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".GamesListActivity"
android:permission="android.permission.INTERNET"
android:screenOrientation="portrait"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SettingsActivity"