Results 1 to 2 of 2
  1. #1
    Verecundus is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default Trying to interface w/ Google's Blogger

    So I'm trying to post to a Blogger account, following Blogger's API instructions on Google's developer's guide. My problem arises in trying to send xml data via POST.

    (Yes, I know that I could download and use Google's java classes to do this. I can't rest until I figure out what's going wrong, though.)

    I try to access http://www.blogger.com/feeds/[blogId]/posts/default with a URLConnection object as follows.
    Java Code:
    URLConnection c = new URL(http://www.blogger.com/feeds/[I][blogId][/I]/posts/default).openConnection();
    c.setRequestProperty("Authorization", "GoogleLogin: auth="+[I][auth key][/I]);
    c.setRequestProperty("METHOD", "POST");
    c.setRequestProperty("Content-type", "application/atom+xml");
    Then I try to pass the sample xml document provided on the developer's guide page:
    Java Code:
    OutputStreamWriter out = new OutputStream(c.getOutputStream());
    out.write("<entry>...</entry>");
    ...Then get the response:
    Java Code:
    BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream()));
    But at this point I get a 403 error.

    Am I sending the data correctly, writing it as a string?

    Am I failing to set the content type? When I check my connection's content type using c.getContentType(), it doesn't show up as xml but rather text/plain.

  2. #2
    Verecundus is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default Solution

    After much travail, it appears that I stumbled upon the solution. For some reason, if I add a slash to the end of the url in the URLConnection, the code works. This is the case even for urls that point to files instead of directories, e.g. "http://directory/sub-directory/file.html"

    (Also, let's not forget the following: )
    Java Code:
    connection.setDoOutput(true);

Similar Threads

  1. Interface?
    By makpandian in forum New To Java
    Replies: 5
    Last Post: 03-26-2009, 11:59 AM
  2. what is the need of interface?
    By makpandian in forum New To Java
    Replies: 1
    Last Post: 03-13-2009, 11:59 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •