Hey guys, thanks for all the help.
I've finally got it fixed.
I had to set the "X-If-No-Redirect" property in the HTTP request header to
'true' in order to force out the redirect address in the response header.
After that a re-POST to the new URL is required.
feels good to see a 201 at long last.
-yijie-
On 6/6/07, John Doe <[EMAIL PROTECTED]> wrote:
>
>
> 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)"
> <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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)" <[EMAIL PROTECTED]>
> > > 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 <[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..- Hide quoted text -
> >
> > > > - Show quoted text -- Hide quoted text -
> >
> > - Show quoted text -
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---