سؤال

I am doing some development about google reader on android platform.

Using google reader api, I can successfully get RSS list. But when I want to mark the RSS item as read, I got "411 Length required" error. This is my code:

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(
            "http://www.google.com/reader/api/0/edit-tag");
    httppost.addHeader("Authorization", auth);

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("i", itemId));
    nameValuePairs.add(new BasicNameValuePair("a",
            "user/-/state/com.google/read"));
    nameValuePairs.add(new BasicNameValuePair("async", "true"));
    nameValuePairs.add(new BasicNameValuePair("T", token));
    nameValuePairs.add(new BasicNameValuePair("s", feedUrl));
    try {
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        Toast.makeText(getApplicationContext(),
                EntityUtils.toString(response.getEntity()),
                Toast.LENGTH_LONG).show();
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Is there any thing wrong?

هل كانت مفيدة؟

المحلول

I have solved this problem myself.

I got this error because the auth part has an additional newline character '\n' at the end. So I remove it using the trim() method.

It works now. I hope this can help somebody.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top