这个请求的原文:
POST /feeds/default/private/full HTTP/1.1
Host: docs.google.com
GData-Version: 3.0
Authorization: <your authorization header here>
Content-Length: 245
Content-Type: application/atom+xml<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <category scheme="http://schemas.google.com/g/2005#kind"
      term="http://schemas.google.com/docs/2007#folder"/>
  <title>Example Folder</title>
</entry>POST /feeds/default/private/full/folder%3Afolder_id/contents HTTP/1.1
Host: docs.google.com
GData-Version: 3.0
Authorization: <your authorization header here>
Content-Length: 244
Content-Type: application/atom+xml<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <category scheme="http://schemas.google.com/g/2005#kind"
      term="http://schemas.google.com/docs/2007#folder"/>
  <title>new subfolder</title>
</entry>我写得是: 
ByteArrayOutputStream buffer = null;
HttpURLConnection _httpURLConnection = null;
URL _url = null;
String postData = "<?xml version='1.0' encoding='UTF-8'?><entry xmlns=\"http://www.w3.org/2005/Atom\"><category scheme=\"http://schemas.google.com/g/2005#kind\"term=\"http://schemas.google.com/docs/2007#folder\"/><title>lpf66fpl</title></entry>";
int lenBody = postData.length();
System.out.println(lenBody);

_url = new URL(resourceURL);
_httpURLConnection = (HttpURLConnection)_url.openConnection();
     _httpURLConnection.setRequestMethod("POST"); 
            //设置连接属性
            _httpURLConnection.setDoOutput(true); //使用 URL 连接进行输出
            _httpURLConnection.setDoInput(true); //使用 URL 连接进行输入
            _httpURLConnection.setUseCaches(false); //忽略缓存
    _httpURLConnection.setRequestProperty("Connection","Keep-Alive");
    
            System.out.println(postData);
System.out.println(auth);
auth = "GoogleLogin auth=" + auth; // GoogleLogin 
System.out.println(auth);
  
     _httpURLConnection.setRequestProperty("Host", "docs.google.com");
     _httpURLConnection.setRequestProperty("GData-Version", "3.0");
         _httpURLConnection.setRequestProperty("Authorization", auth);
         //_httpURLConnection.setRequestProperty("Content-Length", Integer.toString(lenBody));
         //_httpURLConnection.setRequestProperty("Content-Type", "application/atom+xml");
         _httpURLConnection.setRequestProperty("Content-Type","application/atom+xml");
         _httpURLConnection.setRequestProperty("Expect", "100-continue");
         OutputStream output = _httpURLConnection.getOutputStream();
         output.write(postData.getBytes());
         //output.write(postData.getBytes(), 0, lenBody);
         output.flush();
         //_httpURLConnection.connect();
         output.close();          _httpURLConnection.connect();
System.out.println(_httpURLConnection.getResponseCode());

byte[] buff = new byte[1024];
int len = -1;

buffer = new ByteArrayOutputStream();
InputStream in = _httpURLConnection.getInputStream();
while((len = in.read(buff))!= -1) 
{
buffer.write(buff, 0, len);
}我得到
400
java.io.IOException: Server returned HTTP response code: 400 for URL: https://docs.google.com/feeds/default/private/full

解决方案 »

  1.   

    // postData是请求体 下面两种写法哪一个对呢?还是都行?
    //String postData = "<?xml version='1.0' encoding='UTF-8'?>\r\n"  
    // + "<entry xmlns=\"http://www.w3.org/2005/Atom\">\r\n"
    // + "<category scheme=\"http://schemas.google.com/g/2005#kind\"term=\"http://schemas.google.com/docs/2007#folder\"/>\r\n"
    //  + "<title>lpf66fpl</title>\r\n"
    //  + "</entry>\r\n";String postData = "<?xml version='1.0' encoding='UTF-8'?><entry xmlns=\"http://www.w3.org/2005/Atom\"><category scheme=\"http://schemas.google.com/g/2005#kind\"term=\"http://schemas.google.com/docs/2007#folder\"/><title>lpf66fpl</title></entry>";
      

  2.   


     感谢你用QQ联系我我的postData字符串确实写得不对
    scheme=\"http://schemas.google.com/g/2005#kind\" 
    term=\"http://schemas.google.com/docs/2007#folder\"/
    这两句中间 我加了 换行 \r