vb 怎样访问服务器 ?????????????? 查了一下 说是要用 Internet transfer控件,看了一下不太明白,这里要求我POST这个服务器,然后服务器会反馈一个字符串给我,不知道具体怎么实施啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的是用winsock发的。Function WskPost() As BooleanDim i As LongDim PostSu As BooleanPostSu = Falsei = 0StrCommand = "" StrCommand = "POST /noticeCreate.jsp HTTP/1.1" + vbCrLf StrCommand = StrCommand + "Accept: */*" + vbCrLf StrCommand = StrCommand + "Accept-Language: zh-cn" + vbCrLf StrCommand = StrCommand + "Referer: http://119.185.1.182:8888/camion.html" + vbCrLf StrCommand = StrCommand + "x-requested-with: XMLHttpRequest" + vbCrLf StrCommand = StrCommand + "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" + vbCrLf StrCommand = StrCommand + "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; AskTbPTV2/5.9.1.14019; 360SE)" + vbCrLf StrCommand = StrCommand + "Host: 119.185.1.182:8888" + vbCrLf StrCommand = StrCommand + "Content-Length: " & Str(Len(SendMsg)) + vbCrLf StrCommand = StrCommand + "Connection: Keep-Alive" + vbCrLf StrCommand = StrCommand + "Cache-Control: no-cache" + vbCrLf 'strCommand = strCommand + "Accept-Language: zh-CN, zh, *" + vbCrLf StrCommand = StrCommand + "Accept-Encoding: gzip, deflate" + vbCrLf StrCommand = StrCommand + vbCrLf StrCommand = StrCommand + SendMsg + vbCrLfIf wsk1.State <> sckClosed Then wsk1.Closewsk1.RemoteHost = Text1.Textwsk1.RemotePort = Text2.Textwsk1.ConnectDebug.Print StrCommandDo Until i >= 1000 And wsk1.State = sckOpen'MsgBox wsk1.StateIf wsk1.State = 9 Then'stat "错误", ""PostSu = FalseExit DoEnd IfIf wsk1.State = sckConnected Thenwsk1.SendData StrCommandPostSu = TrueExit DoEnd Ifi = i + 1DoEventsLoopWskPost = PostSuEnd Function 用inet控件或者xmlhttp,更简单,自己google下。 用VB6编的程序能直接在VB2008中运行吗? vb调用vc的dll,byte指针参数怎么传递 ASP后台管理,验证问题. Winsock和Access的问题(比较大型) 请教大虾全局变量如何赋初值? 关于VB的面向对象设计 紧急求救!处理断号(100分) 用VB编了一个应用程序,帮助文件如何调用? UDP+Internet, 一个小问题!! VB合并两个pdf文件成1个pdf档的源码 CorelDraw VBA 求曲线上某一点的坐标
Dim i As Long
Dim PostSu As Boolean
PostSu = False
i = 0
StrCommand = "" StrCommand = "POST /noticeCreate.jsp HTTP/1.1" + vbCrLf
StrCommand = StrCommand + "Accept: */*" + vbCrLf
StrCommand = StrCommand + "Accept-Language: zh-cn" + vbCrLf
StrCommand = StrCommand + "Referer: http://119.185.1.182:8888/camion.html" + vbCrLf
StrCommand = StrCommand + "x-requested-with: XMLHttpRequest" + vbCrLf
StrCommand = StrCommand + "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" + vbCrLf
StrCommand = StrCommand + "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; AskTbPTV2/5.9.1.14019; 360SE)" + vbCrLf
StrCommand = StrCommand + "Host: 119.185.1.182:8888" + vbCrLf
StrCommand = StrCommand + "Content-Length: " & Str(Len(SendMsg)) + vbCrLf
StrCommand = StrCommand + "Connection: Keep-Alive" + vbCrLf
StrCommand = StrCommand + "Cache-Control: no-cache" + vbCrLf
'strCommand = strCommand + "Accept-Language: zh-CN, zh, *" + vbCrLf
StrCommand = StrCommand + "Accept-Encoding: gzip, deflate" + vbCrLf
StrCommand = StrCommand + vbCrLf
StrCommand = StrCommand + SendMsg + vbCrLf
If wsk1.State <> sckClosed Then wsk1.Close
wsk1.RemoteHost = Text1.Text
wsk1.RemotePort = Text2.Text
wsk1.Connect
Debug.Print StrCommand
Do Until i >= 1000 And wsk1.State = sckOpen
'MsgBox wsk1.State
If wsk1.State = 9 Then
'stat "错误", ""
PostSu = False
Exit Do
End If
If wsk1.State = sckConnected Then
wsk1.SendData StrCommand
PostSu = True
Exit Do
End If
i = i + 1
DoEvents
Loop
WskPost = PostSu
End Function