这个post请求哪错了?
「已注销」 2010-04-25 03:15:41 这个请求的原文:
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