关于 http://api.fanfou.com/statuses/update.json 的问题

22 views
Skip to first unread message

Juguang XIAO

unread,
Jan 12, 2011, 3:58:31 AM1/12/11
to fanfo...@googlegroups.com
我在用这个API去发布消息,用HTTP POST,内容是:

{"status":"hahaha"}

HTTP 验证好像也过了。但我得到如下回复。是能告诉我错在哪里了。谢谢。


<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>

--
=============
Juguang XIAO
Singapore and Beijing

Juguang XIAO

unread,
Jan 12, 2011, 4:22:10 AM1/12/11
to fanfo...@googlegroups.com
当我用POST做方法的时候,response header是这样的

2011-01-12 17:18:05.948 JXFanfouEngine[6881:207] status code: 200
2011-01-12 17:18:05.949 JXFanfouEngine[6881:207] status code: no error
2011-01-12 17:18:05.950 JXFanfouEngine[6881:207] Server nginx
2011-01-12 17:18:05.951 JXFanfouEngine[6881:207] Expires Sat, 01 Jan
2000 00:00:00 GMT
2011-01-12 17:18:05.951 JXFanfouEngine[6881:207] Content-Encoding gzip
2011-01-12 17:18:05.952 JXFanfouEngine[6881:207] Pragma no-cache
2011-01-12 17:18:05.953 JXFanfouEngine[6881:207]
Cache-Control private, must-revalidate, proxy-revalidate,
post-check=0, pre-check=0
2011-01-12 17:18:05.953 JXFanfouEngine[6881:207] Connection close
2011-01-12 17:18:05.954 JXFanfouEngine[6881:207] Last-Modified Wed,
12 Jan 2011 09:18:05 GMT
2011-01-12 17:18:05.954 JXFanfouEngine[6881:207] Vary Accept-Encoding
2011-01-12 17:18:05.955 JXFanfouEngine[6881:207]
Content-Type application/json; charset=utf-8;
2011-01-12 17:18:05.956 JXFanfouEngine[6881:207] Date Wed, 12 Jan
2011 09:18:05 GMT
2011-01-12 17:18:05.957 JXFanfouEngine[6881:207] Content-Length 20

而response本身是空

--

当用post时,header是:

2011-01-12 17:17:36.263 JXFanfouEngine[6860:207] status code: 200
2011-01-12 17:17:36.264 JXFanfouEngine[6860:207] status code: no error
2011-01-12 17:17:36.265 JXFanfouEngine[6860:207] Max-Age 0
2011-01-12 17:17:36.265 JXFanfouEngine[6860:207] Date 12 Jan 2011
17:17:36 +0800

而response是:

<html>


<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>


谁能帮我一下?谢谢。


2011/1/12 Juguang XIAO <jug...@gmail.com>:

.rex

unread,
Jan 12, 2011, 4:07:28 AM1/12/11
to fanfo...@googlegroups.com
能否将相关的程序搬上来看看? 

另外,该论坛搬到 http://v2ex.com/go/fanfou 了。
rex.



2011/1/12 Juguang XIAO <jug...@gmail.com>
hahaha

Juguang XIAO

unread,
Jan 12, 2011, 4:30:04 AM1/12/11
to fanfo...@googlegroups.com
Objective-C代码。

NSString * json = [NSString stringWithFormat: @"{\"status\":\"%@\"}", status];
NSLog(@"json: %@", json);
static NSString * urlstr = @"http://api.fanfou.com/statuses/update.json";
NSURL * url = [NSURL URLWithString: urlstr];
NSMutableURLRequest * req = [[NSMutableURLRequest alloc] initWithURL: url];
[req setHTTPBody: [ json dataUsingEncoding:NSUTF8StringEncoding]];
[req setHTTPMethod: @"POST"];
[self setupConnectionWithRequest: req];

谢谢

2011/1/12 .rex <r...@zhasm.com>:

--

mcxiaoke

unread,
Jan 12, 2011, 4:39:46 AM1/12/11
to fanfo...@googlegroups.com
POST BODY的数据不要转为JSON格式,直接status=content就可以了

2011/1/12 Juguang XIAO <jug...@gmail.com>

.rex

unread,
Jan 12, 2011, 4:43:01 AM1/12/11
to fanfo...@googlegroups.com
是的,/statuses/update.json 表示返回的数据类型为json。
在具体post 时,只需要将当前数据使用urlencoding处理一下,发过去即可。
例如 status=hello&reply_id=xyz


rex.

Juguang XIAO

unread,
Jan 12, 2011, 5:40:39 AM1/12/11
to fanfo...@googlegroups.com
谢谢。

现在又有个新问题了。刚才为了测试不是HTTP认证的问题,我用错误的密码试了一下。果然返回的也之前不一样,似乎可以证明以前的认证是没有问题的。但现在我碰到了这个“尝试次数过多,请到
http://fanfou.com 登录”。有没有快速的方法解锁啊?谢谢

聚光

2011/1/12 .rex <r...@zhasm.com>:

leen

unread,
Jan 16, 2011, 11:32:28 PM1/16/11
to fanfo...@googlegroups.com
 
j2me 里是这样解决的
byte[] bjson = "status="+URLEncoder.encode(t_msg,"utf-8")+"&in_reply_to_status_id=&source="+Fanfan.API_SOURCE+"&location=".getBytes();
con = (HttpConnection)Connector.open(url);
con.setRequestMethod(HttpConnection.POST);
con.setRequestProperty("Content-Length",
                                    "" + bjson.length);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
if (user != null && password != null) {
      con.setRequestProperty("Authorization",
                                        "Basic " +
                                        BasicAuth.encode(user,
                                                      password));
}
os = con.openOutputStream();
os.write(bjson);
Reply all
Reply to author
Forward
0 new messages