惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - DreamTrue

发布新浪微博API SDK,附Demo地址!! NHibernate N+1问题实例分析和优化 可以防止重复提交的问题 - DreamTrue - 博客园 JavaScript 乘法bug及格式化小数位数 验证电话,手机,小灵通较正确的正则表达式 RegisterClientScriptBlock失效的问题 - DreamTrue - 博客园 程序员朋友们,注意保护眼睛啊!! 基础知识补遗-短路运算符和非短路运算符 用Response将字符串输出到文本(弹出文件下载框) - DreamTrue - 博客园 关于应用WCF X.509证书验证的小结 终于看完了《WCF服务编程》 什么是有状态的服务? 谁能帮我解答《WCF服务编程》第4章实例管理的疑问? 准备购买新书 ADO.Net EF Start (3):实体数据模型(MSDN)EDM1.0版 ADO.Net EF Start (2):Overview asp.net页面防止按钮重复提交的小技巧 ADO.Net EF Start (1):ADO.NET 实体框架概述(MSDN) Asp.net Ajax【客户端三】异步调用
Asp.net Ajax【客户端二】Sys.Net.WebRequest
DreamTrue · 2008-04-25 · via 博客园 - DreamTrue

先从代码开始

客户端请求页面Client.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <script type="text/javascript">
      function pageLoad() {
      }
      function onCompleteCallback(executor,eventArgs)
      {
        if(executor.get_responseAvailable())
        {
           var div=$get("div1");
            div.innerHTML=executor.get_responseData()+"<br/><b>"
                                        +executor.getAllResponseHeaders()+"</b>";
        }
      }
    function call()
    {
        var req=new Sys.Net.WebRequest();
        req.set_url("Server.aspx");
        req.set_httpVerb("Post");
        req.add_completed(onCompleteCallback);
        var body="Name="+encodeURIComponent($get("Text1").value);
        req.set_body(body);
        req.get_headers()["Content-Length"]=body.length;
        req.invoke();
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
    </div>
    <input id="Text1" type="text" />

    <input id="Button1" type="button" value="提交"  onclick="call()"/>
    <div id="div1"></div>
    </form>
</body>
</html>

服务器相应文件Server.aspx代码

protected void Page_Load(object sender, EventArgs e)
{
    Response.Clear();
    Response.Write("Hello,"+Request["name"]);
}

执行结果

未命名

体会:

回调函数写法

function onCompleteCallback(executor,eventArgs)

设置POST方式请求服务器

req.set_httpVerb("Post");

将数据放到Post内部

var body="Name="+encodeURIComponent($get("Text1").value);
req.set_body(body);

Form中的get和post方法,在数据传输过程中分别对应了HTTP协议中的GET和POST方法。二者主要区别如下: 
1、Get是用来从服务器上获得数据,而Post是用来向服务器上传递数据。 
2、Get将表单中数据的按照variable=value的形式,添加到action所指向的URL后面,并且两者使用“?”连接,而各个变量之间使用“&”连接;Post是将表单中的数据放在form的数据体中,按照变量和值相对应的方式,传递到action所指向URL。 
3、Get是不安全的,因为在传输过程,数据被放在请求的URL中,而如今现有的很多服务器、代理服务器或者用户代理都会将请求URL记录到日志文件中,然后放在某个地方,这样就可能会有一些隐私的信息被第三方看到。另外,用户也可以在浏览器上直接看到提交的数据,一些系统内部消息将会一同显示在用户面前。Post的所有操作对用户来说都是不可见的。 
4、Get传输的数据量小,这主要是因为受URL长度限制;而Post可以传输大量的数据,所以在上传文件只能使用Post(当然还有一个原因,将在后面的提到)。 
5、Get限制Form表单的数据集的值必须为ASCII字符;而Post支持整个ISO10646字符集。 
6、Get是Form的默认方法。
 

检查XmlHttp是否返回成功

if(executor.get_responseAvailable())


以下是Sys.Net.WebRequestExecutor 类

Sys.Net.WebRequestExecutor Class Members

Name

Description

  • Sys.Net.WebRequestExecutor.abort Method

Stops additional processing of the current request.

  • Sys.Net.WebRequestExecutor.executeRequest Method

Executes a Web request.

  • Sys.Net.WebRequestExecutor.getAllResponseHeaders Method

Gets all the response headers for the current request.

  • Sys.Net.WebRequestExecutor.getResponseHeader Method

Gets the value of a specific response header based on the header's name.

  • Sys.Net.WebRequestExecutor aborted Property

Gets a value indicating whether the request associated with the executor was aborted.

  • Sys.Net.WebRequestExecutor responseAvailable Property

Gets a value indicating whether the request completed successfully.

  • Sys.Net.WebRequestExecutor responseData Property

Gets the text representation of the response body.

  • Sys.Net.WebRequestExecutor started Property

Gets a value indicating whether the executor has started processing the request.

  • Sys.Net.WebRequestExecutor statusCode Property

Gets a success status code.

  • Sys.Net.WebRequestExecutor statusText Property

Gets status information about a request that completed successfully.

  • Sys.Net.WebRequestExecutor timedOut Property

Gets a value indicating whether the request timed out.

  • Sys.Net.WebRequestExecutor xml Property

Attempts to get the response to the current request as an XMLDOM object.