5 messages in com.googlegroups.google-base-data-apiRe: 411 error. Length Requried| From | Sent On | Attachments |
|---|---|---|
| Shawn | 13 Dec 2007 18:28 | |
| Jeff S | 14 Dec 2007 14:19 | |
| shallway | 14 Dec 2007 17:35 | |
| M....@1210Solutions.com | 18 Dec 2007 07:43 | |
| shallway | 18 Dec 2007 17:02 |
| Subject: | Re: 411 error. Length Requried![]() |
|---|---|
| From: | M....@1210Solutions.com (M....@1210solutions.com) |
| Date: | 12/18/2007 07:43:53 AM |
| List: | com.googlegroups.google-base-data-api |
Had the same problem. For anyone else reading this watch out for leading and trailing whitespace when passing in the HTTP headers. For me I had trailing whitespace on the token I was passing in. The error doesn't really point you in that direction, but check check and double check the headers!!!
On Dec 15, 1:36 am, "shallway" <shal...@gmail.com> wrote:
Hey Jeff, You saved my life! Thank you very much. Yes just like you pointed out. The issue came from there. In fact I did found the html code very weird generated after the script got the session token. It's like this :
<html><body><h1>Main Page</h1><form method="post" name="form_insert"> <input type="hidden" name="token" value="CMfR9ci5ARCmu8aOAw " /> ##### GHOSTS HERE! How did they get here? <input type="submit" name="action" value="insertitem" /></form></body></html>
Thanks Jeff. You guys are cool! Shawn
-----Original Message----- From: Goog...@googlegroups.com
[mailto:Goog...@googlegroups.com] On Behalf Of Jeff S Sent: 2007年12月15日 6:20 To: Google Base Data API Subject: Re: 411 error. Length Requried
Hi Shawn,
It might help to take a look at the packets being transmitted between your script and Google Base, it's often easier to spot problems that way. In this case I think I may have spotted something, an errant ' character following the Authorization header. This might explain why the headers you are setting don't seem to be working. Did removing the quote help?
Thank you,
Jeff
P.S. If you need a start on capturing packets take a look at this article:
http://code.google.com/support/bin/answer.py?answer=71567&topic=11983
This article on command line curl might also be helpful.
http://code.google.com/support/bin/answer.py?answer=78451&topic=11983
On Dec 13, 6:29 pm, Shawn <shal...@gmail.com> wrote:
Will you help me please! Here's what's confusing me these days. Environment: I have Apache2.2/PHP5.2.3 with cUrl PHP integreted. The curl function was tested out thru some testing page. 1.I downloaded this sample script from here:http://code.google.com/apis/base/samples/php/demo.php.txt. And it worked fine. 2.Since the sample script dealt with items of Recipe type and what I needed was to work with items of Product type. I decided
to write a new one to do the job. 3.In my script, I made up a test item in xml form named $test_item and it looks like the following:
$test_item = '<?xml version="1.0"?>'."\n"; $test_item .= '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">'; $test_item .= '<id>$id</id>'; $test_item .= '<title type="text">'.$title.'</title>'; $test_item .= '<link rel="alternate" type="text/html" href='. $link.' />'; $test_item .= '<content>'.$description.'</content>'; $test_item .= '<g:item_type>'.$item_type.'</g:item_type>'; $test_item .= '<g:author>'; $test_item .= '<g:name>'.$author_name.'</g:name>'; $test_item .= '<g:email>'.$author_email.'</g:email>'; $test_item .= '</g:author>'; $test_item .= '<g:image_link>'.$p_image.'</g:image_link>'; $test_item .= '<g:product_type>'.$p_type.'</g:product_type>'; $test_item .= '<g:price>'.$p_price.'</g:price>'; $test_item .= '</entry>';
4.The token function was ok. Then I thought it would be quit simple just to create a curl object and send the above data to
google base. Here is the code:
function insertItem($item, $sessionToken){ global $devkey; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/base/feeds/ items'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); //for debugging purpose curl_setopt($ch, CURLOPT_POSTFIELDS, $item); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: AuthSub token='.$sessionToken.'\'', 'X-Google-Key: key=$devkey', 'Content-Type: application/atom+xml', )); $result = curl_exec($ch); curl_close($ch); return $result; }
5.I passed $test_itme to insertItem and it looked like this: insertItem($test_item, $token). Then I got this : Length Required POST requests require a Content-length header. 6.I tried to see what was curl doing. So I add 2 line2 to the above function : $info = curl_getinfo($ch); var_dump($info); 7.I noticed the 'Content-Type' field was 'text/html;charset=utf-8' from the output.While it should be 'application/atom+xml'
just like the code setted. 8.No matter what I set it to, it remained 'text/html' in the output. So I thought there might be something wrong in my curl
version or something. But since the sample script run ok. Why cant mine? 9.I thought well maybe it's the item xml I created in my script had something wrong. So I copy and paste the recipe xml from
the sample script and replaced it with the one in my script. Error remained. 10. Well it's great! It must be the script itself. I didn't know where but it must be some tricks in there. Since the sample
script was ok. So I thought maybe I just replace the xml data in it with that in my script. And I did that. Error remained.
Save my Ass. Thanks. Shawn




