8 messages in com.googlegroups.google-calendar-help-dataapiRe: Post new entry using HTTP request...
FromSent OnAttachments
John Doe04 Jun 2007 02:55 
Bala05 Jun 2007 07:24 
Lane LiaBraaten (Google)05 Jun 2007 10:57 
John Doe05 Jun 2007 20:42 
John Doe05 Jun 2007 20:44 
Lane LiaBraaten (Google)05 Jun 2007 21:29 
John Doe05 Jun 2007 23:41 
John Doe The Intern06 Jun 2007 02:56 
Subject:Re: Post new entry using HTTP request - in Java
From:John Doe (klo@gmail.com)
Date:06/05/2007 11:41:16 PM
List:com.googlegroups.google-calendar-help-dataapi

Hi Lane,

That did help, but led me to another problem.. The error got promoted from 400 to "Error 401 Authorization required"

I'm currently setting a new connection to the feed,

url = new URL("http://www.google.com/calendar/feeds/default/private/ full"); conn = (HttpURLConnection)url.openConnection();

Does creating this new connection void my authentication token that I obtain when I was connected to "https://www.google.com/accounts/ ClientLogin".

Or should I be just connected to www.google.com and using the same connection throughout?

thanks, -yijie-

On Jun 6, 12:30 pm, "Lane LiaBraaten (Google)" <api.@gmail.com> wrote:

Hi,

I think this line is causing a problem for you: con.setRequestProperty("Content-Type", "application/atom +xml"); There shouldn't be a space between "appliation/atom" and "+xml"

Hope that helps, Lane

On Jun 5, 8:42 pm, John Doe <klo@gmail.com> wrote:

Hi Lane,

Thanks for the reply.. I've followed the code that you sent me, but still meet with the following errors: - '400: Bad Request' for url: 'http://www.google.com/calendar/feeds/ default/private/full' - java.io.FileNotFoundException

Is that url the one that I should use for posting anentry? And must I specify my email and passwd again in the header, or anything else that I may missing out?

I've checked through everything, but can't figure out what's wrong here.

My code : ~~~~~~~~~~~~~ String data = "<... (the sample xml code from the Developer's Guide: Protocol) ... > " ; HttpURLConnection con =
(HttpURLConnection)(newURL("http://www.google.com/calendar/feeds/default/private/full")).openConnection(); con.setDoOutput(true); con.setDoInput(true); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/atom +xml"); con.setRequestProperty("Authorization", "GoogleLogin auth=" + auth); // auth contains my authentication token. outputStream = con.getOutputStream(); outputStream.write(data.getBytes()); outputStream.close(); ~~~~~~~~~~~~~~

thanks again, appreciate it. -yijie-

On Jun 6, 1:57 am, "Lane LiaBraaten (Google)" <api.@gmail.com> wrote:

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 thePOSTrequest and the authorization header connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/atom +xml"); connection.setRequestProperty("Authorization", "GoogleLogin auth=" + token);

//Postthe 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 <klo@gmail.com> 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/em...@gma@(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..- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -