aardio 官方社区

 找回密码
 注册会员

QQ登录

只需一步,快速开始

搜索
查看: 33410|回复: 19

我的第一个whttp库post程序

  [复制链接]

117

主题

1103

回帖

6572

积分

六级会员

积分
6572
发表于 2011-7-2 20:17:35 | 显示全部楼层 |阅读模式
import win.ui;

/*DSG{{*/
var winform = win.form( bottom=143;scroll=1;right=183;text="aardio Form" )
winform.add(
button2={ bottom=119;right=75;left=15;top=86;font=LOGFONT( name=
"宋体";h=-12 );z=6;text="刷新";cls="button" };
edit={ bottom=64;right=160;left=88;top=48;font=LOGFONT( name=
"宋体";h=-12 );z=3;text="";edge=1;cls="edit" };
button={ bottom=118;text=
"注册";left=101;top=85;font=LOGFONT( name="宋体";h=-12 );z=1;right=161;cls="button" };
picturebox={ bottom=72;right=96;left=16;text=
"picturebox";top=40;font=LOGFONT( name="宋体";h=-12 );transparent=1;z=2;cls="picturebox" };
static2={ text=
"帐号";bottom=24;right=72;left=24;top=8;font=LOGFONT( name="宋体";h=-12 );z=5;transparent=1;cls="static" };
edit2={ bottom=24;right=168;left=88;top=8;font=LOGFONT( name=
"宋体";h=-12 );z=4;text="";edge=1;cls="edit" }
)
/*}}*/

winform.show();

import inet.whttp;
whttp=inet.whttp()


winform.button2.oncommand =
function(id,event){
    whttp.beginRequest(
"http://www.icodo.com/inc/vdimgck.php","GET",);
    whttp.send();
    cookie=whttp.readHeader(
"Set-Cookie");
    winform.picturebox.image =whttp.read()
    whttp.endRequest();
        
}


winform.button.oncommand =
function(id,event){
   
var postData = "forward=?user=&member_type=1&username="+winform.edit2.text+"&pass1=199241&pass2=199241&email=sdfdssafgd%40qq.com&code="+winform.edit.text+"&xieyi=1";
   
var html= whttp.post("http://www.icodo.com/login/reg_save.php",postData,"Cookie:"+ cookie);
   
if(string.find(html,"恭喜你")){
        win.msgbox(
"注册成功了","aardio");
    }
   
elseif(string.find(html,"对不起")){
        win.msgbox(
"验证码错了","aardio");
    }
   
else{
        win.msgbox(html,
"其他错误");
    }
}

win.loopMessage();
return winform;





原帖地址
http://aardio.com/thread-307-1-1.html

0

主题

4

回帖

48

积分

一级会员

积分
48
发表于 2011-7-2 21:49:41 | 显示全部楼层
是值得参考。

52

主题

1270

回帖

7276

积分

荣誉会员

积分
7276
发表于 2011-7-2 21:53:00 | 显示全部楼层
恭喜啊 ,这个例子确实值得参考,谢谢分享

65

主题

880

回帖

5033

积分

荣誉会员

积分
5033
发表于 2011-7-2 22:03:28 | 显示全部楼层
很好很强大

56

主题

412

回帖

3788

积分

荣誉会员

积分
3788
发表于 2011-7-4 09:32:45 | 显示全部楼层
支持支持{:soso_e102:}

51

主题

212

回帖

1548

积分

四级会员

积分
1548
发表于 2011-7-11 08:49:13 | 显示全部楼层
有个问题:运行程序后,多点几次刷新后再点注册就会出错。

查找后发现后:第二次点刷新后,cookie就会变成NULL。如何解决呢?

56

主题

412

回帖

3788

积分

荣誉会员

积分
3788
发表于 2011-7-11 09:37:21 | 显示全部楼层
o00viw 发表于 2011-7-11 08:49
有个问题:运行程序后,多点几次刷新后再点注册就会出错。

查找后发现后:第二次点刷新后,cookie就会变 ...

for(i=1;20;1){
    whttp.beginRequest(
"http://www.icodo.com/inc/vdimgck.php","GET",);
    whttp.send();
    cookie=whttp.readHeader(
"Set-Cookie");
   
if(cookie){break ;}
   
sleep(1000)
}
if(!cookie){
    win.msgbox(
"网络连接失败","aardio")
   
return ;
}
winform.picturebox.image =whttp.read()
whttp.endRequest();

51

主题

212

回帖

1548

积分

四级会员

积分
1548
发表于 2011-7-11 09:49:17 | 显示全部楼层
cbtan 发表于 2011-7-11 09:37
for(i=1;20;1){
    whttp.beginRequest("http://www.icodo.com/inc/vdimgck.php","GET",);
    whttp ...

应该不是次数这个原因造成的吧。我试好几次都出现20个NULL。

56

主题

412

回帖

3788

积分

荣誉会员

积分
3788
发表于 2011-7-11 10:04:25 | 显示全部楼层
本帖最后由 cbtan 于 2011-7-11 10:07 编辑
o00viw 发表于 2011-7-11 09:49
应该不是次数这个原因造成的吧。我试好几次都出现20个NULL。

我好像误会你意思了。。。。。

48

主题

542

回帖

3328

积分

五级会员

积分
3328
发表于 2011-7-16 21:14:44 | 显示全部楼层
有时间再注意看看

3

主题

45

回帖

1126

积分

四级会员

积分
1126
发表于 2011-7-16 22:30:38 | 显示全部楼层
本帖最后由 aiwen 于 2011-7-16 22:35 编辑
o00viw 发表于 2011-7-11 08:49
有个问题:运行程序后,多点几次刷新后再点注册就会出错。

查找后发现后:第二次点刷新后,cookie就会变 ...

做了个判断,就可以暂时解决这个问题,我测试了一下,注册是成功的。
cookie=null;
winform.button2.oncommand = function(id,event){
        math.randomize();
    whttp.beginRequest("http://www.icodo.com/inc/vdimgck.php?r="+math.random(),"GET",);
    whttp.send();
    if(!cookie){
            cookie=whttp.readHeader("Set-Cookie");
            }


    winform.picturebox.image =whttp.read()
    whttp.endRequest();
}

1

主题

17

回帖

99

积分

一级会员

积分
99
发表于 2011-7-18 09:04:06 | 显示全部楼层
好啊,学习的实例,不错
1

52

主题

1270

回帖

7276

积分

荣誉会员

积分
7276
发表于 2011-7-26 02:08:47 | 显示全部楼层
修改了一下, 不需要处理cookie  测试注册成功
import win.ui;
/*DSG{{*/
var winform = win.form( bottom=143;scroll=1;text="aardio Form";right=183 )
winform.add(
button2={ bottom=119;text=
"刷新";left=15;top=86;font=LOGFONT( name="宋体";h=-12 );z=6;right=75;cls="button" };
edit={ bottom=64;right=160;left=88;top=48;font=LOGFONT( name=
"宋体";h=-12 );z=3;text="";edge=1;cls="edit" };
button={ bottom=118;right=161;left=101;top=85;font=LOGFONT( name=
"宋体";h=-12 );z=1;text="注册";cls="button" };
picturebox={ bottom=72;text=
"picturebox";left=16;right=96;top=40;font=LOGFONT( name="宋体";h=-12 );z=2;transparent=1;cls="picturebox" };
static2={ text=
"帐号";bottom=24;right=72;left=24;top=8;font=LOGFONT( name="宋体";h=-12 );transparent=1;z=5;cls="static" };
edit2={ bottom=24;right=168;left=88;top=8;font=LOGFONT( name=
"宋体";h=-12 );z=4;text="";edge=1;cls="edit" }
)
/*}}*/

winform.show();

import inet.whttp;
whttp=inet.whttp()

winform.button2.oncommand =
function(id,event){
    math.randomize();
    img = whttp.get(
"http://www.icodo.com/inc/vdimgck.php?r=" + math.random());
    winform.picturebox.image =img
   
}

winform.button.oncommand =
function(id,event){
   
var postData = "forward=?user=&member_type=1&username="+winform.edit2.text+"&pass1=199241&pass2=199241&email=sdfdssafgd%40qq.com&code="+winform.edit.text+"&xieyi=1";
   
var html= whttp.post("http://www.icodo.com/login/reg_save.php",postData);
   
if(string.find(html,"恭喜你")){
        win.msgbox(
"注册成功了","aardio");
    }
   
elseif(string.find(html,"对不起")){
        win.msgbox(
"验证码错了","aardio");
    }
   
else{
        win.msgbox(html,
"其他错误");
    }
   
    whttp.close()
}


win.loopMessage();
return winform;



点评

good  发表于 2011-7-26 08:53

18

主题

57

回帖

408

积分

二级会员

积分
408
发表于 2012-9-30 06:10:55 | 显示全部楼层
做个标记

0

主题

8

回帖

49

积分

新手入门

积分
49
QQ
发表于 2015-8-3 00:33:59 | 显示全部楼层
学习

2

主题

3

回帖

32

积分

新手入门

积分
32
发表于 2015-12-4 12:02:38 | 显示全部楼层
做个标记,学习学习

0

主题

14

回帖

149

积分

一级会员

积分
149
发表于 2016-3-7 13:52:37 | 显示全部楼层
做个标记,学习学习做个标记,学习学习做个标记,学习学习

0

主题

10

回帖

185

积分

一级会员

积分
185
发表于 2016-3-10 18:14:10 | 显示全部楼层
学习了

13

主题

294

回帖

1790

积分

荣誉会员

积分
1790
发表于 2016-3-10 18:39:09 | 显示全部楼层
本来就不需要自己处理cookie,

服务端并不是每次都在响应头的set-cookie里把所有cookie都写一遍,只是在设置cookie的时候才会写,所以不是每次都有这个头。

响应头中的set-cookie,与请求头中的cookie: 格式是不一样的
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

手机版|未经许可严禁引用或转载本站文章|aardio.com|aardio 官方社区 ( 皖ICP备09012014号 )

GMT+8, 2025-3-20 09:23 , Processed in 0.088804 second(s), 32 queries .

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表