Discuz教程网

WinHttp.WinHttpRequest.5.1使用详解

[复制链接]
authicon dly 发表于 2012-2-15 22:44:53 | 显示全部楼层 |阅读模式
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>无标题文档</title>
  6. <script language="javascript" type="text/javascript">
  7. function getCookie(name)
  8. {
  9. var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
  10. if(arr != null) {
  11. var uid = unescape(arr[2]).match(new RegExp("userid=(\\d+)"));
  12. return (uid == null) ? "" : uid[1];
  13. //return uid[1];
  14. }else{
  15. return "";
  16. }
  17. }

  18. /*function sendData(objform)
  19. {
  20. //alert(objform.username);
  21. if (window.ActiveXObject && !window.XMLHttpRequest)
  22. {
  23. window.XMLHttpRequest = function()
  24. {
  25. var MSXML = ['Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP'];
  26. for (var i = 0; i < MSXML.length; i++)
  27. {
  28. try {
  29. return new ActiveXObject(MSXML[i]);
  30. }
  31. catch (e){}
  32. }
  33. return null;
  34. };
  35. }

  36. var xmlHttp = new XMLHttpRequest();
  37. xmlHttp.open("GET","http://www.baidu.com", false);
  38. xmlHttp.send();
  39. var book = xmlHttp.responseText;
  40. alert(book);

  41. }*/
  42. </script>

  43. <%
  44. Function BytesToBstr(body)
  45. dim objstream
  46. set objstream = Server.CreateObject("adodb.stream")
  47. objstream.Type = 1
  48. objstream.Mode =3
  49. objstream.Open
  50. objstream.Write body
  51. objstream.Position = 0
  52. objstream.Type = 2
  53. objstream.Charset = "GB2312"
  54. '转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP调用有中文字符的网页得到的将是乱码
  55. BytesToBstr = objstream.ReadText
  56. objstream.Close
  57. set objstream = nothing
  58. End Function

  59. if Request.ServerVariables("REQUEST_METHOD") = "POST" then
  60. dim username,password
  61. dim http,url,revalue,data
  62. username = request.Form("username")
  63. password = request.Form("password")
  64. url = "http://www.hf777.com/xxx"
  65. if username = "" or password = "" then
  66. response.Write("不能为空!")
  67. response.end
  68. end if

  69. data = "name="&username&"&pass="&password

  70. Set http = server.CreateObject("WinHttp.WinHttpRequest.5.1")
  71. http.Option(4) = 13056
  72. http.Option(6) = True '为True时,当请求的页面中有跳转时,抓取跳转页面信息.False相反不抓取
  73. http.Open "POST", url, False
  74. http.setrequestheader "Referer","http://localhost/zhbb/default.asp"
  75. http.setrequestheader "User-Agent", "Mozilla/4.0"
  76. http.setrequestheader "Connection", "Keep-Alive"
  77. http.setrequestheader "Content-Length",len(data)
  78. http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  79. http.Send data

  80. 'revalue = BytesToBstr(http.responsebody)
  81. revalue = http.responseText
  82. response.write(revalue)
  83. response.end
  84. end if
  85. %>
  86. </head>

  87. <body>
  88. <form id="form1" name="form1" method="post" action="">
  89. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  90. <tr>
  91. <td height="25" align="right"> 用户名:</td>
  92. <td><input name="username" type="text" class="input_text01" id="username" /></td>
  93. <td width="60" align="right">密码:</td>
  94. <td><input name="password" type="text" class="input_text01" id="password" /></td>
  95. <td >  <a href="#" class="underline" onclick="document.form1.submit()" >登录</a>  <a href="#" class="underline">注册新用户</a></td>
  96. <td width="330"> </td>
  97. <td align="right">安徽赛区0-3岁宝宝网络投票网站</td>
  98. </tr>
  99. </table>
  100. </form>
  101. </body>
  102. </html>
复制代码



上一篇:JS入门之ActiveXObject对象[js对象]
下一篇:利用javascript操作本地文件(读写txt文件)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 11:00

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

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