标题:asp接口问题
只看楼主
wfdszds_zds
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-10-21
结帖率:0
已结贴  问题点数:20 回复次数:3 
asp接口问题
需要从asp页面向另一运用程序传递文件,应怎样提交?
搜索更多相关主题的帖子: 接口 
2013-10-21 21:49
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
得分:10 
首先确定这个另一应用程序,在哪,在服务器上,还是客户端上。
2013-10-22 09:55
wfdszds_zds
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-10-21
得分:0 
在服务器上,给了地址和端口
2013-10-24 23:05
ysf0181
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:55
帖 子:914
专家分:2385
注 册:2006-10-4
得分:10 
Class xhttp
 private cset,sUrl,sError,sCanShu
 Private Sub Class_Initialize()
  'cset="UTF-8"
  cset="GB2312"
  sError=""
 end sub
 
 Private Sub Class_Terminate()
 End Sub
 
 Public Property LET URL(theurl)
  sUrl=theurl
 end property
 public property GET BasePath()
  BasePath=mid(sUrl,1,InStrRev(sUrl,"/")-1)
 end property
 public property GET FileName()
  FileName=mid(sUrl,InStrRev(sUrl,"/")+1)
 end property
 public property GET Html()
  Html= BytesToBstr(getBody(sUrl))
  'Html= getBody(sUrl)
 end property
 
 Public Property LET URLCanShu(theurls)
  sCanShu = theurls
  
 end property
 public property GET HtmlPost()
  HtmlPost = BytesToBstr(getBodyPost(sUrl,sCanShu))
  'Html= getBody(sUrl)
 end property
 
 public property GET xhttpError()
  xhttpError=sError
 end property
 
 private Function BytesToBstr(body)
  on error resume next
  'Cset:GB2312 UTF-8
  dim objstream
  set objstream = Server.CreateObject("adodb.stream")
  with objstream
  .Type = 1 '
  .Mode = 3 '
  .Open     
  .Write body  '
  .Position = 0 '
  .Type = 2  '
  .Charset = Cset  '
  BytesToBstr = .ReadText '
  .Close
  end with
  set objstream = nothing
 End Function
 


 private function getBody(surl)
  on error resume next
  dim xmlHttp
  'Set xmlHttp=server.createobject("Msxml2.XMLHTTP.4.0")
  'set xmlHttp=server.createobject("Microsoft.XMLHTTP")
  set xmlHttp=server.createobject("MSXML2.ServerXMLHTTP")
  xmlHttp.setTimeouts 10000,10000,10000,30000
  'xmlHttp.open "GET",surl,false
  xmlHttp.open "GET",surl,false
  'xmlHttp.SetRequestHeader "Referer","AL_HTML" '将HTTP头中来源页变为AL_HTML
  xmlHttp.send
  if xmlHttp.readystate=4 then
  'if xmlHttp.status=200 then
     getBody = xmlhttp.responsebody
      'getBody = xmlhttp.responseText
  'end if
  else
   getBody=""
  end if
  
  if Err.Number<>0 then
  sError=Err.Number
  Err.clear
  else
  sError=""
  end if
  set xmlHttp=nothing
 end function
 
 '添加文本域的名称和值

 
 private function getBodyPost(surl,sCanShu)
  on error resume next
  dim xmlHttp
  Charset = "gb2312"
  'response.write sCanshu
  'response.end
  'postContent ="xueyuan="& Server.UrlEncode(xueyuan)&"&username="&Server.UrlEncode(xueyuan)&""
 ' response.write  postContent
  'response.end
  'AddForm "xueyuan", request("xueyuan") '文本域的名称和内
  'Set xmlHttp=server.createobject("Msxml2.XMLHTTP.4.0")
  'set xmlHttp=server.createobject("Microsoft.XMLHTTP")
  set xmlHttp=server.createobject("MSXML2.ServerXMLHTTP")
  xmlHttp.setTimeouts 10000,10000,10000,30000
  xmlHttp.open "POST",surl,false
  'xmlHttp.SetRequestHeader "Referer","AL_HTML" '将HTTP头中来源页变为AL_HTML
  xmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" '无该项,不能 POST 参数
  xmlHttp.send sCanShu
  if xmlHttp.readystate=4 then
  'if xmlHttp.status=200 then
     getBodyPost = xmlhttp.responsebody
      'getBody = xmlhttp.responseText
  'end if   
  else
     getBodyPost = ""
  end if
  'response.write BytesToBstr(getBodyPost)
  'response.end
  if Err.Number<>0 then
     sError=Err.Number
     Err.clear
  else
     sError=""
  end if
  set xmlHttp=nothing
 end function
 
 Public function saveimage(tofile)
  on error resume next
  dim objStream,imgs
  imgs=getBody(sUrl)
  Set objStream = Server.CreateObject("ADODB.Stream")
  with objStream
  .Type =1
  .Open
  .write imgs
  .SaveToFile server.mappath(tofile),2
  .Close()
  end with
  set objstream=nothing
 end function
end class 'Class xhttp
'------------------------------------------------------------Class xhttp-------------------------------------------------




'使用范例
'读取URL 的HTML
'dim myHttp
'set myHttp = new xhttp
'myHttp.URL="http://www.baidu.com"
'Response.Write(myHttp.html)
'response.end
'''''''''''


'保存远程图片到本地
'myHttp.URL="http://www.baidu.com/img/logo.gif"
'myHttp.saveimage "myfile.gif"
'为防止xhttp卡死的情况,使用超时,错误处理
'dim sHtmlcode,iStep
'myHttp.URL="http://www.
'sHtmlcode=myHttp.html
'iStep=0
'do while myHttp.xhttpError=""
' Response.Write("ERROR: AGAIN!<br />")
' sHtmlcode=myHttp.html
' iStep=iStep+1
' if iStep=1 then
'  Response.Write("ERROR:OVER!<hr />")
'  exit do
' end if
'loop
'Response.Write(sHtmlcode)

'set myHttp=nothing

ASP讨论QQ群:251346273
2013-10-25 09:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-422310-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.186039 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved