문제

I'm trying to parse some html using jsoup (1.3.3) in my android activity. When I call this code

Jsoup.connect("http://www.google.com").get();

It works fine in android 2.1 and 2.2 but in 1.6 I get a "java.io.IOException: 403 Error loading URL".

I'm using the emulator to test this and I've noticed that admob ads are also not showing in 1.6 but they work in 2.0, 2.1 and 2.2.

Using the web browser in the 1.6 emulator does work so I'm pretty confident the problem is in my code somewhere.

Is there some extra permission I need for internet access in 1.6 that you don't need in 2.0+?

This is how my manifest file is structured, does the position of the uses-permission tag have any effect?

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.foo.bar"
  android:versionCode="1"
  android:versionName="1.0"
  android:installLocation="auto">

<application android:icon="@drawable/icon" 
android:label="@string/app_name" 
android:theme="@android:style/Theme.NoTitleBar" 
android:name="blahblah" 
android:description="@string/app_desc">

    <activity android:label="@string/app_name" android:name=".activities.MainMenu">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

<activity android:name=".activities.FullList" android:label="@string/app_name"/>

<!-- The application's publisher ID assigned by AdMob -->
<meta-data android:value="blahblahblah" android:name="ADMOB_PUBLISHER_ID" />

</application>
<uses-sdk android:minSdkVersion="4"/>

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

</manifest>

I've tried creating a new project from scratch with just a hello world screen that uses the Jsoup.connect() method and that works fine on the same 1.6 emulator, so it must be a code problem but I can't figure it out.

도움이 되었습니까?

해결책

JSOUP internally uses HttpURLConnection. Here is the line throwing exception.

The internet connection is OK (or else it would throw exception earlier) and you are getting a reply from server which is: 403 HTTP FORBIDDEN

Is there some kind of login in place? Do check that you can open the same URL in browser on the same device/emulator.

다른 팁

Try inserting /uses-sdk near the end of the script or try deleting /uses-permission with each surrounded with angle brackets

I've tried creating a new project from scratch with just a hello world screen that uses the Jsoup.connect() method and that works fine on the same 1.6 emulator, so it must be a code problem but I can't figure it out.

Try putting a test usage of this early in your application startup (or if that causes an ANR timeout, add a "test" button)

Make a copy of your application and comment a lot of things out

Somewhere between your minimal test which works and your full application which doesn't, there lies an important difference. Recursively divide the difference and conquer it...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top