java.io.IOException:403错误使用JSoup加载URL

时间:2012-04-18 20:59:04

标签: android jsoup

我正在尝试使用jsoup登录fiverr并提取Android应用程序的订单。这是我的代码。我从fiverr那里得到了403。假设我错过了什么。任何想法。

  Connection.Response res;
    try {
        res = Jsoup.connect("http://fiverr.com/login")
                .header("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2")
                .userAgent("Mozilla")  
                .data("user_session[username]", "myusername")
                .data("user_session[password]", "mypassword")
                .data("user_session[remember_me]", "1") 
                .method(Method.POST)
                .execute();

        Document doc = res.parse();
        String __utma = res.cookie("__utma");
        String __utmb = res.cookie("__utmb");
        String __utmc = res.cookie("__utmc");
        String __utmz = res.cookie("__utmz");
        String _fiverr_sessions = res.cookie("_fiverr_sessions");
        String _jsuid = res.cookie("_jsuid");
        String fiverr_auth_info = res.cookie("fiverr_auth_info");
        String km_ai = res.cookie("km_ai");
        String km_lv = res.cookie("km_lv");
        String km_ni = res.cookie("km_ni");
        String km_uq = res.cookie("km_uq");
        String km_vs = res.cookie("km_vs");
        String kvcd = res.cookie("kvcd");





        Document doc2 = Jsoup.connect("http://fiverr.com/users/myusername/manage_orders/type/priority")
                .header("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2")
                .userAgent("Mozilla")  
                .cookie("__utma", __utma)
                .cookie("__utmb", __utmb)
                .cookie("__utmc", __utmc)
                .cookie("__utmz", __utmz)
                .cookie("_fiverr_sessions", _fiverr_sessions)
                .cookie("_jsuid", _jsuid)
                .cookie("fiverr_auth_info", fiverr_auth_info)
                .cookie("km_ai", km_ai)
                .cookie("km_lv", km_lv)
                .cookie("km_ni", km_ni)
                .cookie("km_uq", km_uq)
                .cookie("km_vs", km_vs)
                .cookie("kvcd", kvcd)
                .get();

        TextView TextLocation = (TextView)findViewById(R.id.textView1);
        TextLocation.setVisibility(View.VISIBLE);
        TextLocation.setText((CharSequence) doc2.html());
        System.out.println(doc2.html());


    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

这是错误:

  04-18 20:25:54.444: W/System.err(552): java.io.IOException: 403 error loading URL http://fiverr.com/login
  04-18 20:25:54.464: W/System.err(552):    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:414)
  04-18 20:25:54.475: W/System.err(552):    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:391)
  04-18 20:25:54.535: W/System.err(552):    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:157)
  04-18 20:25:54.565: W/System.err(552):    at com.newrock.my5._MainActivity.onCreate(_MainActivity.java:35)
  04-18 20:25:54.575: W/System.err(552):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  04-18 20:25:54.595: W/System.err(552):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
  04-18 20:25:54.595: W/System.err(552):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
  04-18 20:25:54.635: W/System.err(552):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  04-18 20:25:54.684: W/System.err(552):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
  04-18 20:25:54.684: W/System.err(552):    at android.os.Handler.dispatchMessage(Handler.java:99)
  04-18 20:25:54.715: W/System.err(552):    at android.os.Looper.loop(Looper.java:130)
  04-18 20:25:54.755: W/System.err(552):    at android.app.ActivityThread.main(ActivityThread.java:3683)
  04-18 20:25:54.755: W/System.err(552):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-18 20:25:54.764: W/System.err(552):    at java.lang.reflect.Method.invoke(Method.java:507)
  04-18 20:25:54.794: W/System.err(552):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  04-18 20:25:54.824: W/System.err(552):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  04-18 20:25:54.844: W/System.err(552):    at dalvik.system.NativeStart.main(Native Method)
  04-18 20:25:55.364: I/ActivityManager(68): Displayed com.newrock.my5/._MainActivity: +6s716ms
  04-18 20:26:05.184: D/dalvikvm(142): GC_EXPLICIT freed 53K, 47% free 3123K/5831K, external 2183K/2603K, paused 86ms
  04-18 20:26:10.315: D/dalvikvm(243): GC_EXPLICIT freed 6K, 51% free 2725K/5511K, external 716K/1038K, paused 148ms
  04-18 20:26:15.285: D/dalvikvm(282): GC_EXPLICIT freed 8K, 44% free 3366K/5959K, external 716K/1038K, paused 101ms
  04-18 20:26:20.345: D/dalvikvm(311): GC_EXPLICIT freed 10K, 52% free 2776K/5703K, external 716K/1038K, paused 126ms
  04-18 20:26:25.444: D/dalvikvm(345): GC_EXPLICIT freed 7K, 44% free 3533K/6279K, external 716K/1038K, paused 134ms
  04-18 20:26:30.434: D/dalvikvm(356): GC_EXPLICIT freed 3K, 51% free 2718K/5511K, external 716K/1038K, paused 81ms
  04-18 20:29:37.864: D/SntpClient(68): request time failed: java.net.SocketException: Address family not supported by protocol
  04-18 20:29:46.895: D/dalvikvm(122): GC_CONCURRENT freed 439K, 49% free 3096K/6023K, external 716K/1038K, paused 10ms+5ms
  04-18 20:34:37.887: D/SntpClient(68): request time failed: java.net.SocketException: Address family not supported by protocol
  04-18 20:37:42.078: I/dalvikvm(128): Jit: resizing JitTable from 512 to 1024
  04-18 20:39:37.905: D/SntpClient(68): request time failed: java.net.SocketException: Address family not supported by protocol
  04-18 20:44:37.921: D/SntpClient(68): request time failed: java.net.SocketException: Address family not supported by protocol

2 个答案:

答案 0 :(得分:1)

403错误表示您没有访问指定URL所需的权限。

您确定正确处理身份验证吗?

答案 1 :(得分:0)

这是一个身份验证问题。在尝试对帐户执行任何操作时,请确保实施特定于fiverr API的所有身份验证。即使oAuth存在问题,您也可以获得此代码403 ...