注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

沉默蜂B4A安卓编程

国内资料最全的B4A资料库

 
 
 

日志

 
 

[原创]B4A基于ASP远程访问MDB数据库(七)  

2014-04-21 19:45:22|  分类: B.网络 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
下面是服务模块HttpJob代码


#Region Module Attributes
#StartAtBoot: False
#End Region

'HttpUtils2 version 2.00
'Service module
Sub Process_Globals
Private hc As HttpClient
Private TaskIdToJob As Map
Public TempFolder
Private taskCounter As Int
End Sub

Sub Service_Create
TempFolder = File.DirInternalCache
hc.Initialize("hc")
TaskIdToJob.Initialize
End Sub

Sub Service_Start (StartingIntent As Intent)
End Sub

Sub Service_Destroy

End Sub

Public Sub SubmitJob(job As HttpJob) As Int
taskCounter = taskCounter + 1
TaskIdToJob.Put(taskCounter, job)
If job.Username <> "" AND job.Password <> "" Then
hc.ExecuteCredentials(job.GetRequest, taskCounter, job.Username, job.Password)
Else
hc.Execute(job.GetRequest, taskCounter)
End If
Return taskCounter
End Sub

Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Response.GetAsynchronously("response", File.OpenOutput(TempFolder, TaskId, False), _
True, TaskId)
End Sub

Sub Response_StreamFinish (Success As Boolean, TaskId As Int)
If Success Then
CompleteJob(TaskId, Success, "")
Else
CompleteJob(TaskId, Success, LastException.Message)
End If
End Sub

Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
If Response <> Null Then
Try
Log(Response.GetString("UTF8"))
Catch
Log("Failed to read error message.")
End Try
Response.Release
End If
CompleteJob(TaskId, False, Reason)
End Sub

Sub CompleteJob(TaskId As Int, success As Boolean, errorMessage As String)
Dim job As HttpJob
job = TaskIdToJob.Get(TaskId)
TaskIdToJob.Remove(TaskId)
job.success = success
job.errorMessage = errorMessage
job.Complete(TaskId)
End Sub

  评论这张
 
阅读(183)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017