
1 cbsw 2014-06-14 20:28:51 +08:00 用多说不就调用给的那段脚本就行了吗,站点静态的都行,应该不需要自己处理跨域问题 |
3 cbsw 2014-06-14 20:47:50 +08:00 @yangkeao 这里不就可以匿名吗 http://dev.duoshuo.com/threads/51ef7387d137f48920000084 话说你是要自己写一个多说吗? |
4 yangkeao OP @cbsw 难道API里面的匿名评论指的是 可以随便打个名字?? 还以为可以不输入名字。。。 尝试着用给的脚本,绕过本地对于输入名字的验证后提交,Bad Request。 所以我什么都懂了。。。。 那就算了吧。(我只是想用他的API,没有自己写一个的意思。) |
8 cbsw 2014-06-14 21:26:22 +08:00 你是在用 django 吗,我曾经也对 django 的跨域问题比较纠结,规定表单 post 一定要加 csrf_token ,不过似乎可以通过 ajax 提交表单来绕开 django 对 post 表单的检查 |
9 ysdj 2014-06-14 23:18:40 +08:00 在服务端调用API啊 |
11 txlty 2014-06-14 23:25:23 +08:00 抓包看了一下,跨域的秘密就在这里: 多说API接口返回的HTTP头信息里允许跨域读取。 Access-Control-Allow-Origin 表示允许哪个域读取信息。这个是添加站点时指定的。 |
13 txlty 2014-06-14 23:32:57 +08:00 每个多说域名对应一个允许的站点域。 所以,调用API时调用添加站点时设置的多说域名,比如: http://[你设置的多说域名].duoshuo.com/posts/create.json 而不是 http://api.duoshuo.com/posts/create.json |
14 yangkeao OP @txlty XMLHttpRequest cannot load http://api.duoshuo.com/posts/create.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. |
16 simonyan 2014-06-14 23:41:29 +08:00 前端是jquery,后端是node js;http://blog.csdn.net/dabiaoyanjun/article/details/27569681 |
17 yangkeao OP @txlty XMLHttpRequest cannot load http://videa.duoshuo.com/posts/create.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://idea.vdon.cn' is therefore not allowed access. 允许的站点域是设置里面的首页网址吗? |
18 txlty 2014-06-15 00:46:14 +08:00 |
19 emric 2014-06-15 03:11:26 +08:00 //api.duoshuo.com/posts/create.jsonp 使用 jsonp, 详见文档~ |
25 yangkeao OP @txlty 十分感谢 抓包发现是http://[你设置的多说域名].duoshuo.com/api/posts/create.json 后来更正后,400. 发现是参数少了几个,只填了必选。有几个是没登录必填的,我没有,所以400了 |
28 reorx 2014-06-15 12:10:14 +08:00 @cbsw 没用过多说不知道它具体怎么做,但跨域是 HTTP 协议上的东西,跟框架没有关系,现在无外乎两种方式: jsonp 和 CORS,后者请查看 mozilla 文档 https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS 你说的那个 csrf_token 是所谓的跨站请求伪造,为了给模拟登录和其他请求增加难度,和跨域不一样的。 |
30 HunterPan 2014-06-15 18:37:40 +08:00 jsonp? |