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

推荐订阅源

人人都是产品经理
人人都是产品经理
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy International News Feed
Simon Willison's Weblog
Simon Willison's Weblog
I
Intezer
Spread Privacy
Spread Privacy
The Hacker News
The Hacker News
P
Palo Alto Networks Blog
TaoSecurity Blog
TaoSecurity Blog
S
Secure Thoughts
Google Online Security Blog
Google Online Security Blog
H
Heimdal Security Blog
N
News | PayPal Newsroom
Attack and Defense Labs
Attack and Defense Labs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园 - 【当耐特】
Webroot Blog
Webroot Blog
小众软件
小众软件
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
PCI Perspectives
PCI Perspectives
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
Cloudbric
Cloudbric
AI
AI
WordPress大学
WordPress大学
博客园 - 聂微东
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
Hacker News: Ask HN
Hacker News: Ask HN
H
Hacker News: Front Page
博客园 - Franky
V
V2EX
Schneier on Security
Schneier on Security
G
GRAHAM CLULEY
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
H
Help Net Security
量子位
S
Security @ Cisco Blogs
大猫的无限游戏
大猫的无限游戏
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Recorded Future
Recorded Future
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
C
Cisco Blogs
S
Security Affairs

博客园 - IMustDo

Delphi TWebBrowser编程简述(转帖) delphi 如何将XML格式的字符串导入ClientDataSet中 用WebBrowser实现HTML界面的应用 delphi TStringList的用法 使用VSS 的Shadow folder的一点问题 Delphi 字符串操作 delphi 最快速编码 URLDecode URLEncode Delphi 2007 如何安装控件 .NET 3.5和VS 2008中的ASP.NET AJAX(转帖) VS.net 2008 beta2 新功能 VS 2008 和 .NET 3.5 Beta 2 发布了(转帖) .Net平台开发的技术规范与实践精华总结(转载收藏) 35 岁前程序员要规划好的四件事(转载) ASP.NET程序中常用的三十三种代码(转载) 40种网站设计常用技巧(转载) Visual C#常用函数和方法集汇总(收藏) 访问母版页上的成员 用缓存吧,反正现在内存白菜价,不用白不用。 在MasterPage中使用javascript获取对象
Javascript+xmlhttp调用Webservice以及注意事项
IMustDo · 2007-09-10 · via 博客园 - IMustDo

 1 如何处理: 请求格式无法识别 这种调用过程的错误?
 2  -----------注意vs.net写wevservie供调用的时------
 3 <webServices> 
 4 <protocols> 
 5 <add name="HttpPost" /> 
 6 <add name="HttpGet" /> 
 7 </protocols> 
 8 </webServices> 
 9 把这个复制到你项目里的web.config里的<system.web>节点下面应该就可以了
10 
11 下面是具体调用过程:
12 
13 

1.  创建webservice,为了免于落俗我稍稍修改了创建webserice的默认webmethod。^_^
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace 
= "http://tempuri.org/")]
[WebServiceBinding(ConformsTo 
= WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
    public Service () 
{

        
//Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }


    [WebMethod]
    public string SayHelloTo(string Name) 
{
        
return "Hello "+Name;
    }

    
}

还是俗了点。:)

2. js调用webservice+xmlhttp的实现部分。

<html>
<title>
Call webservice 
with javascript and xmlhttp.
</title>
<body>
<script language="javascript"> 

//Test function with get method.
function RequestByGet(data)

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
//Webservice location.
var URL="http://localhost:1323/WebSite6/Service.asmx/SayHelloTo?Name=Zach";
xmlhttp.Open(
"GET",URL, false); 
xmlhttp.SetRequestHeader (
"Content-Type","text/xml; charset=utf-8"); 
xmlhttp.SetRequestHeader (
"SOAPAction","http://tempuri.org/SayHelloTo"); 
xmlhttp.Send(data); 
var result = xmlhttp.status; 
//OK
if(result==200
document.write(xmlhttp.responseText); 
}
 
xmlhttp 
= null
}
 

//Test function with post method
function RequestByPost(value)
{
var data;
data 
= '<?xml version="1.0" encoding="utf-8"?>'; 
data 
= data + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'; 
data 
= data + '<soap:Body>'; 
data 
= data + '<SayHelloTo xmlns="http://tempuri.org/">'; 
data 
= data + '<Name>'+value+'</Name>'; 
data 
= data + '</SayHelloTo>'; 
data 
= data + '</soap:Body>'; 
data 
= data + '</soap:Envelope>'; 

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
var URL="http://localhost:1323/WebSite6/Service.asmx";
xmlhttp.Open(
"POST",URL, false); 
xmlhttp.SetRequestHeader (
"Content-Type","text/xml; charset=gb2312"); 
xmlhttp.SetRequestHeader (
"SOAPAction","http://tempuri.org/SayHelloTo"); 
xmlhttp.Send(data); 
document.write( xmlhttp.responseText); 

}


</Script>

<input type="button" value="CallWebserviceByGet" onClick="RequestByGet(null)">
<input type="button" value="CallWebserviceByPost" onClick="RequestByPost('Zach')">

</body>
</html>
对于使用post方法需要发送的那堆东东可以在webservice的测试页面中找到,自己拼凑加上对应的参数就可以。

我发现用post方法的时候响应很慢,是因为用Post方法时发送的数据多的原因吗?