Hi,

While the Java client library isn't compatible with Java 1.4.2, it can
still be a great reference.  I found this example in the sample/gbase/
basic/InsertExample.java file that I think will work in 1.4.2:

  public void postItem(String token) throws IOException {
    HttpURLConnection connection = (HttpURLConnection)(new
URL(ITEMS_FEED)).openConnection();

    connection.setDoInput(true);
    connection.setDoOutput(true);

    // Set the properties of the connection: the Http method, the
content type
    // of the POST request and the authorization header
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type", "application/atom
+xml");
    connection.setRequestProperty("Authorization", "GoogleLogin auth="
+ token);

    // Post the data item
    OutputStream outputStream = connection.getOutputStream();
    outputStream.write(DATA_ITEM.getBytes());
    outputStream.close();

    // Retrieve the output
    int responseCode = connection.getResponseCode();
    InputStream inputStream;
    if (responseCode == HttpURLConnection.HTTP_CREATED) {
      inputStream = connection.getInputStream();
    } else {
      inputStream = connection.getErrorStream();
    }

    // write the output to the console
    System.out.println(toString(inputStream));
  }


Hope that helps,
Lane

On Jun 4, 2:55 am, John Doe <[EMAIL PROTECTED]> wrote:
> Hi there, I need help with this rather fundamental task here but I'm
> an absolute newbie at communicating using HTTP requests.
>
> I need to add/edit/delete calendar events on my JSP site. I know I shd
> be using the Java Client Library but for some reason I have to stick
> to java 1.4.2 (gdata runs on ver 1.5 though) on my server so I need to
> find some other ways of doing it.
>
> So right now I'm trying to do things using the java URLConnection
> object.
>
> ~~~~~~~~~~~~~~~
> String xmlfeed = http://www.google.com/calendar/feeds/[EMAIL 
> PROTECTED]/private-(magic
> cookie)/basic
> URL url =newURL(xmlfeed);
> URLConnection conn = url.openConnection();
> conn.setDoOutput(true);
>
> BufferedReader rd =newBufferedReader(new
> InputStreamReader(conn.getInputStream()));
> while ((line = rd.readLine()) != null) { out.println(line); }
> rd.close();
> ~~~~~~~~~~~~~~~
>
> by doing this, i can retrieve and print out the XML contents of my
> calendar.
>
> However, I have no idea how to format and send aPOSTrequest to my
> XML feed.
>
> I tried :
> ~~~~~~~~~~~~~~~~
> String data = "POST" + xmlfeed;
> data += " <entryxmlns='http://www.w3.org/2005/Atom'... (the sample
> xml code from the Developer's Guide: Protocol) ... > "
> OutputStreamWriter wr =new
> OutputStreamWriter(conn.getOutputStream());
> wr.write(data);
> wr.flush();
> ~~~~~~~~~~~~~~~~~
>
> The response that I received was a  HTTP/1.0 400 Bad Request .
>
> Can anyone guide me on what I should do to submit a proper request?
> I've searched through the forums and references, but everybody seems
> to know how to do it, except for me apparently.
>
> many thanks in advance..


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Calendar Data API" group.
To post to this group, send email to 
[email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to