`

Send Http Request For Asp with json

阅读更多
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> 
<% Response.CodePage=65001%> 
<% Response.Charset="UTF-8" %> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Asp Http Post Request</title>
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>  
  <body>

<script language="JScript" runat="Server">
	function toObject(json) {
		eval("var o=" + json);
		return o;
	}
</script>

<!-- #include file="json.asp" -->

<%
	Function GetHttpPage(url, charset) 
		Dim http 
		Set http = Server.createobject("Microsoft.XMLHTTP")
		http.Open "GET", url, false
		http.Send() 
		If http.readystate<>4 Then
			Exit Function 
		End If 
		GetHttpPage = BytesToStr(http.ResponseBody, charset)
		Set http = Nothing
	End Function
	
	Function PostHttpRequest(url,params,charset)
		Dim xmlHttp 
		Set xmlHttp = Server.CreateObject("Microsoft.XMLHTTP") 
		xmlHttp.open "POST ", url, False 

		xmlHttp.setRequestHeader "Content-Type", "application/json"
		xmlHttp.setRequestHeader "User-Agent", "User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.8.1.14) Gecko/200804" 
		xmlHttp.setRequestHeader "Connection", "keep-alive" 

		xmlHttp.send params 
		
		If xmlHttp.readystate<>4 Then
			Exit Function 
		End If 
			PostHttpRequest = BytesToStr(xmlHttp.ResponseBody, charset)
		Set xmlHttp = Nothing
	End Function

	Function BytesToStr(body, charset)
		Dim objStream
		Set objStream = Server.CreateObject("Adodb.Stream")
		objStream.Type = 1
		objStream.Mode = 3
		objStream.Open
		objStream.Write body
		objStream.Position = 0
		objStream.Type = 2
		objStream.Charset = charset
		BytesToStr = objStream.ReadText 
		objStream.Close
		Set objStream = Nothing
	End Function

%>


<%
	Dim reqUrl 
		reqUrl = "http://www.baidu.com"
	Dim reqCharset  
		reqCharset = "UTF-8"
	
	If code <> "" Then 
		Dim jString
		jString = PostHttpRequest(reqUrl,"{}",reqCharset)
		Dim jsonval
		Set jsonval = toObject(jString)
%>

<%
	End If
%>

<font  size="2" color="red"> <br/>
	<br/>
	<br/>
	<br/>
	-----------------------运行本程序前确保以下组件存在------------------- <br/>
		Adodb.Stream (ADO 数据流对象, 常见被用在无组件上传程序中) √  <br/>
		Microsoft.XMLHTTP (Http 组件, 常在采集系统中用到) √  <br/>
		服务器脚本引擎 VBScript/5.8.23141 , JScript/5.8.23259 √ <br/>
	----------------------------------------------------------------------------------------- <br/>
</font>

  </body>
</html>


  

提供一个测试asp发送http request(get/post),并且可以将数据发送并接收的例子。传输的数据格式使用json。附件中有完整代码。

分享到:
评论

相关推荐

    SendHTTPRequest

    SendHTTPRequest 我需要的东西

    SendHTTPRequest123

    SendHTTPRequest 我需要的代码

    C# how to send http request

    C# how to send http request

    Beginning.JSON.1484202031

    Beginning JSON provides you with the skill set required for reading and writing properly validated JSON data. The first two chapters of the book will discuss the foundations of JavaScript for those ...

    PB12.5 POST方式提交JSON到HTTP API(亲测可用)

    Power Builder 12.5,使用ole MSXML2.ServerXMLHTTP方式,对接WEB API,以JSON方式提交数据,POST/GET方式均可。

    send wyre postmain json 接口文档

    send wyre postmain json 接口文档

    send-json:Node.js 模块通过 http 将对象作为 JSON 发送

    var sendJson = require ( 'send-json' ) ; var server = http . createServer ( function ( req , res ) { sendJson ( res , { hello : 'world' } ) ; } ) ; server . listen ( 3000 ) ; 或者您可以像这样向 http...

    An Asynchronous HTTP Request WinINet Wrapper in C++

    Class FCHttpRequest is responsible for implementing send HTTP request and receive response, it's a wrapper class for WinINet. Class FCHttpRequestManager is a management of FCHttpRequest, responsible ...

    网络获取json解析json以及子线程显示

    HttpUtil.sendHttpRequest(url, new HttpCallbackListener() { @Override public void onFinish(String response) { showResponse(response); } @Override public void onError(Exception e) { } });*/ ...

    json序列化jar包

    JavaScript Object Notation (aka JSON) is a very popular alternative to XML for transmitting data to the web browser. Flexjson is a lightweight library for serializing and deserializing Java objects ...

    APIZZA Send Request Plugins-2.2.0.zip

    名称:APIZZA Send Request Plugins ---------------------------------------- 版本:2.2.0 作者:http://apizza.cc/ 分类:开发者工具 ---------------------------------------- 概述:apizza.cc 网站发送请求...

    send-json:跨域和浏览器发送json

    发送json 在所有浏览器之间跨所有浏览器发送json。 安装 $ component install yields/send-json 原料药 发送(url,obj,fn) 执照 (麻省理工学院)

    unity解析json对象

    When I looked into the issue, I tried a few of the C# implementations listed on http://json.org, but found them to be too complicated to work with and expand upon. So, I've written a very simple ...

    session,request区别

    session,request之间的区别,session在系统登录之后系统自动产生,request只能在页面之间存在

    jansson-send.zip_JSON_jansson

    简短的应用关于json的操作,分享一下,也留个备份

    http POST 发送工具下载

    Using Send HTTP Tool you will be able to create and send HTTP request in just few seconds. Select your HTTP method, enter your URL. Modify HTTP header, choose the cache policy and other HTTP options ...

    java SMS for send and receive

    java SMS for send and receive

    基于JSON的REST框架RestyGWT.zip

    JSONValue request = ...resource.post().json(request).send(new JsonCallback() { public void onSuccess(Method method, JSONValue response) { System.out.println(response); } public void onFailure(Method ...

    Send to Kindle for PC

    这是Kindle资源的pc传输客户端,将文件上传到kindle服务器和...普通的文档在直接copy到kindle以后,通常会出现显示问题,但是通过Send to Kindle软件传输的文档,已经在服务器进行了重新排版,文档不会出现乱码等情况。

Global site tag (gtag.js) - Google Analytics