这个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
...全文
118 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
justwalking 2010-04-26
  • 打赏
  • 举报
回复
帮顶,接分...........
「已注销」 2010-04-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 gao125210 的回复:]

up up up
[/Quote]

感谢你用QQ联系我

我的postData字符串确实写得不对
scheme=\"http://schemas.google.com/g/2005#kind\"
term=\"http://schemas.google.com/docs/2007#folder\"/
这两句中间 我加了 换行 \r
gao125210 2010-04-25
  • 打赏
  • 举报
回复
up up up
「已注销」 2010-04-25
  • 打赏
  • 举报
回复
// 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>";
「已注销」 2010-04-25
  • 打赏
  • 举报
回复
关于出现的问题我得另一个帖子写得更加详细
http://topic.csdn.net/u/20100423/20/5c192aa3-eed2-4972-b186-606f00ad8259.html

大家帮顶呀

100散分啦

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧