0

どのように機能するのかよくわかりませんが、JSON-RPC で認証してからページをリクエストする必要があります。ユーザー名とパスワードが正しいかどうかを確認するためのこのコードがありますが、この情報を使用してページをリクエストする方法がわかりません..

    List<Cookie> cook;
    public void postData(String method, Object ... params) throws JSONException {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://www.examp;e.com/json-rpc/");

        try {
            // Add your data

            String methodandp = "{id:3, method:" + method + ", params:[" + params[0].toString()+ ", " + params[1].toString() + "]}";

            StringEntity a = new StringEntity(methodandp);
            httppost.setEntity(a);
            Log.i("ClientActivity: request", httppost.getMethod().toString());
            Log.i("ClientActivity: request", nameValuePairs.toString());


            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);


            Header[] head = response.getAllHeaders();

            Log.i("ClientActivity", response.getStatusLine().toString());
            String responseString = EntityUtils.toString(response.getEntity());
            responseString = responseString.trim();
            JSONObject jsonResponse = new JSONObject(responseString);
            Log.i("ClientActivity", jsonResponse.toString());
            String cookie = "";

            for(int i = 0; i < head.length; i++){
                Log.i("ClientActivity: response", head[i].toString());
                if(head[i].toString().contains("Set-Cookie")){
                    cookie = (head[i].toString()).replace("Set-Cookie: ", "");
                    cook = ((AbstractHttpClient) httpclient).getCookieStore().getCookies();
                    if (cook.isEmpty()) {
                        System.out.println("None");
                    } else {
                        for (int x = 0; x < cook.size(); x++) {
                            Log.i("ClientActivity", "-" + cook.get(x).toString());
                        }
                    }
                    Log.i("ClientActivity: Cookie", cookie);
                }
            }
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }
    } 

成功し、すべての適切なデータが返されますが、使用方法がわかりません。

4

1 に答える 1

1

今見てみると、これは実際には非常に単純でした。認証されていることを確認したら、同じ HttpClient (Cookie を保持する) を使用して他のファイルを要求し、MultipartEntity を使用して Web サーバーにファイルをプッシュできます。

于 2012-06-15T08:55:02.207 に答える