这个请求的原文:
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
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
解决方案 »
- public String(String original)
- 指点迷津----nio服务器架构问题
- 关于两个applet之间互相通讯的简单问题
- SWING组件中获得容器的问题
- JGoodies中文乱码问题?
- Linux下的j2sdk-1_4_2_04-linux-i586-rpm.bin怎么才能运行?
- java.awt.Graphics.copyArea(int, int, int, int, int, int) 怎么用?
- java i/o 我看不懂呀!
- ********************我想通过WEB页面形式使用户录音,并且将录音信息保存到我的WEB服务器,请问大家怎么解决?********************
- 怎样发布java Application?
- 请教 java中如何输出一个变量的反值?
- 编程
//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>";
感谢你用QQ联系我我的postData字符串确实写得不对
scheme=\"http://schemas.google.com/g/2005#kind\"
term=\"http://schemas.google.com/docs/2007#folder\"/
这两句中间 我加了 换行 \r