Sending a post request, receiving different errors: 400: Premature end of file

139 views
Skip to first unread message

Albo

unread,
Apr 11, 2015, 8:54:57 PM4/11/15
to mitappinv...@googlegroups.com
Hi,

I am working on an app for a school project. I need to be able to access the contacts, delete a specific contact, and create a contact (with specific name and phone fields pre-filled out). I've been able to access the google contacts api, and I've been able to access the contacts, as well as delete contacts, however, with the post command, I am not able to create a contact.

Google says:

I've thought to build the attached file. I've dumbed it down, so I can at least get it to create a contact, (and I'll add info later), but even with just this, I get an error 400 Premature end of file. I've tried the grayed out part instead of empty text, but I removed it just to get the contact creation part down.
If the content-type is anything else, I get a different error saying content type (...) is not a valid type. So I think it has to remain as atom+xml

I'm thinking it's possible that I need an xml file of sorts to upload with this, but I am not sure at all.

I'm basing most of this on this: https://puravidaapps.com/contacts.php

and the post command on these: 

Any help with something like this?
Screen Shot 2015-04-11 at 8.46.30 PM.png

Taifun

unread,
Apr 12, 2015, 10:38:27 AM4/12/15
to mitappinv...@googlegroups.com
see my answer here https://puravidaapps.com/contacts.php#q
Taifun

Albo

unread,
Apr 13, 2015, 3:07:13 PM4/13/15
to mitappinv...@googlegroups.com
Hi Taifun,

Thanks for responding. I tried this, and I seem to be getting closer, however, I keep getting an error 400 "The prefix ":atom" for element ":atom:entry" is not bound"

Can you provide just a little bit more help on how to format the POST text? Here's what I've done so far.

Thanks!
Screen Shot 2015-04-13 at 3.04.53 PM.png

Taifun

unread,
Apr 13, 2015, 6:02:38 PM4/13/15
to mitappinv...@googlegroups.com
remove multiple spaces in your text, I just tried the following format and it worked fine
Taifun
PS: sorry, I have seen, my example xml fórmat on my webpage was not correct, this is now corrected...

<gd:name><gd:givenName>Elizabeth</gd:givenName><gd:familyName>Bennet</gd:familyName><gd:fullName>Elizabeth Bennet</gd:fullName></gd:name>
<atom:content type='text'>Notes</atom:content>
<gd:phoneNumber rel='http://schemas.google.com/g/2005#work' primary='true'>(206)555-1212</gd:phoneNumber>
</atom:entry>


Albo

unread,
Apr 13, 2015, 6:37:44 PM4/13/15
to mitappinv...@googlegroups.com
Hi Taifun,

Thank you so much!! It worked.. but there's no names that went up with it. I got a 201, which is correct, but the contact name didn't register.

In my google contacts, I see the phone number for 206 555 1212, but there's no name associated with it. When you tried it, did you get a contact name as well? Ugh so close!!! I really appreciate your help. You've been extremely helpful!

Thanks.

Taifun

unread,
Apr 13, 2015, 6:51:48 PM4/13/15
to mitappinv...@googlegroups.com
you are correct.. sorry, I don't know what could be the problem
according to the documentation the format is correct, see also https://developers.google.com/gdata/docs/2.0/elements?csw=1#gdName
feel free to do a Google search, also stackoverflow probably can help
Taifun

Albo

unread,
Apr 13, 2015, 9:08:09 PM4/13/15
to mitappinv...@googlegroups.com
So, I figured that out. I needed another HTTP Header with 

GData-Version: 3.0


However, now trying to figure out how to add the contact to the "My Contacts" Group, instead of Other Contacts. Should be simpler, now that I have the formatting. Thanks so much Taifun. I'll update this one last time, with my finished block in case people run into similar issues, or are curious as to how I did it.

Albo

unread,
Apr 13, 2015, 9:40:43 PM4/13/15
to mitappinv...@googlegroups.com
Last Update:

Here's how I got it all to work.

Clarification: Textbox 2 was a first name. Textbox 4 was a last name. Textbox 3 was for phone number.
The blank text block in between 2 and 4 (The second time around) actually contains a single space, in order to get proper formatting.
Group membership base/6/ is the "My Contacts" group. If you don't include that, it defaults to Other Contacts.
Screen Shot 2015-04-13 at 9.39.46 PM.png

Taifun

unread,
Apr 14, 2015, 10:32:00 AM4/14/15
to mitappinv...@googlegroups.com
great detective work! congratulations!
Taifun
Reply all
Reply to author
Forward
0 new messages