I am developing a program for my institution to create shared contacts on 
our domain and I have run into a problem.
 
I'm not sure what part of my code is making the server return this error, 
but the error is:

Java.io.IOException: Server returned HTTP response code: 400 for URL: 
https://www.google.com/m8/feeds/contacts/<domain>/full

Here is my code:

//Code begins here

String line, data;
data = 

<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' 
xmlns:gd='http://schemas.google.com/g/2005'> <atom:category 
scheme='http://schemas.google.com/g/2005#kind' 
term='http://schemas.google.com/contact/2008#contact' /> <gd:name> 
<gd:givenName>"

+ itemFirstName + "</gd:givenName> <gd:familyName>" + itemLastName + 
"</gd:familyName> 
<gd:fullName>" + itemFirstName + " " + itemLastName + "</gd:fullName> 
</gd:name> <gd:email rel='http://schemas.google.com/g/2005#work' 
primary='true' address='" + *itemEmail* + "' displayName='" + itemFirstName 
+ " " + itemLastName+ "' /> <gd:phoneNumber 
rel='http://schemas.google.com/g/2005#work' primary='true'>" + itemPhone + 
"</gd:phoneNumber> 
<gd:organization><gd:orgTitle>" + itemTitle + 
"</gd:orgTitle><gd:orgDepartment>" + itemDept + 
"</gd:orgDepartment></gd:organization> 
</atom:entry>

 URL url = 

*new* URL("https://www.google.com/m8/feeds/contacts/<domain>/thin");

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setDoOutput(

*true*);

conn.setRequestMethod(

"POST");

conn.setRequestProperty(

"Content-Type", "application/atom+xml");

conn.setRequestProperty(

"Authorization","GoogleLogin auth=<code here>");

conn.setRequestProperty(

"GData-Version","3.0");

OutputStreamWriter writer = 

*new* OutputStreamWriter(conn.getOutputStream());

 //write parameters

writer.write(data);

writer.flush();

 StringBuffer answer = 

*new* StringBuffer();

BufferedReader reader = 

*new* BufferedReader(*new* InputStreamReader(conn.getInputStream()));

 *while* ((line = reader.readLine()) != *null*)

answer.append(line);

 writer.close();

reader.close();

 System.

*out*.println(conn.getResponseCode());

System.

*out*.println(conn.getResponseMessage());

 } 

*catch* (MalformedURLException ex) {

ex.printStackTrace();

} 

*catch* (IOException ex) {

ex.printStackTrace();
}
 
// Code ends here
 
I am posting a string to the server, its in xml format with tags and 
everything. I'm not sure what I am doing wrong... Is it allowed to post a 
string as xml?
 
Thank you.
Jake

-- 
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" 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://code.google.com/apis/contacts/community/forum.html

Reply via email to