weex icon indicating copy to clipboard operation
weex copied to clipboard

关于stream fetch传递参数的问题

Open zjalen opened this issue 10 years ago • 4 comments

`stream.fetch({`
    			method: 'POST',
    			url: `'http://***.**.**.**/login/dologin.html',`
                        body: {phone:"138*****224"},
    			type:'json',
    		},function(ret) {

body部分的格式究竟是怎么样的,查了很多,没有看到官方说明里介绍任何body格式的写法,试了字符串,json字符串,都不行,服务器端收到body都是空的,跪求给个说明。

zjalen avatar Nov 23 '16 16:11 zjalen

自己结吧,初学不熟练,看了很久,试了几次才试出来,body要用字符串"phone=133*****3333",GET方法要把body整合在url里,POST要单独写在body里,要不然不成功。

zjalen avatar Nov 24 '16 02:11 zjalen

代码?

spiritelf avatar Dec 12 '16 05:12 spiritelf

没有更好办法? 会有乱码问题吗?

spiritelf avatar Dec 12 '16 06:12 spiritelf

@spiritelf POST方式提交 `var data = "username="+phone+"&code="+verify_code; var headers = {'X-Requested-With':'XMLHttpRequest'}; stream.fetch({ method: 'POST', url: 'https://www.****.cn/admin/dologin.html?', body:data; headers:headers; type:'json', },function(ret) {

},function(response){

});`

GET方式提交 `var data = "username="+phone+"&code="+verify_code; stream.fetch({ method: 'GET', url: 'https://www.****.cn/admin/dologin.html?'+data, type:'json', },function(ret) {

},function(response){

});`

官方文档具体格式讲的不很清楚,这个应该是比较完善的了,试过没什么问题,没有乱码出现

zjalen avatar Dec 19 '16 09:12 zjalen