返回的也是200呀,可怎么登录不上去呢???请高手指教呀~~Private Sub Form_Load()Set objhttp = CreateObject("MSXML2.XMLHTTP")
Set xmlDOC = CreateObject("MSXML.DOMDocument")
strWebserviceURL = "http://www.csdn.net/member/logon.asp"
'设置参数及其值
strRequest = "login_name=用户名&password=密码&cookietime=0&x=42&y=10"
objhttp.Open "POST", strWebserviceURL, False
'设置这个Content-Type很重要
objhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
'SOAPAction这个Header头同样可以在sample中找到
objhttp.setRequestHeader "SOAPAction", "http://tempuri.org/Add"
objhttp.setRequestHeader "Content-Length", Len(strWebserviceURL)objhttp.Send (strRequest)
bOK = xmlDOC.Load(objhttp.responseXML)
'看看状态值
MsgBox objhttp.Status
MsgBox objhttp.StatusText
'objHTTP.Status=200,这里就可以处理返回的xml片段了
'如果需要,可以替换返回的xml字符串当中的<和>
If objhttp.Status = 200 Then MsgBox "Success"
xmlStr = xmlDOC.xml
xmlStr = Replace(xmlStr, "<", "<", 1, -1, 1)
xmlStr = Replace(xmlStr, ">", ">", 1, -1, 1)MsgBox xmlStrEnd Sub
Set xmlDOC = CreateObject("MSXML.DOMDocument")
strWebserviceURL = "http://www.csdn.net/member/logon.asp"
'设置参数及其值
strRequest = "login_name=用户名&password=密码&cookietime=0&x=42&y=10"
objhttp.Open "POST", strWebserviceURL, False
'设置这个Content-Type很重要
objhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
'SOAPAction这个Header头同样可以在sample中找到
objhttp.setRequestHeader "SOAPAction", "http://tempuri.org/Add"
objhttp.setRequestHeader "Content-Length", Len(strWebserviceURL)objhttp.Send (strRequest)
bOK = xmlDOC.Load(objhttp.responseXML)
'看看状态值
MsgBox objhttp.Status
MsgBox objhttp.StatusText
'objHTTP.Status=200,这里就可以处理返回的xml片段了
'如果需要,可以替换返回的xml字符串当中的<和>
If objhttp.Status = 200 Then MsgBox "Success"
xmlStr = xmlDOC.xml
xmlStr = Replace(xmlStr, "<", "<", 1, -1, 1)
xmlStr = Replace(xmlStr, ">", ">", 1, -1, 1)MsgBox xmlStrEnd Sub
MsgBox objhttp.responseText
下面是返回的内容~~
我还是先查查关于编码的内容再问问你吧,thx~~
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="Refresh" content="2;URL=/Member/Passport.asp">
<meta http-equiv="Content-Type" content="text/html" ; charset="gb2312">
<title>CSDN_Login????</title>
</head>
<body>
<br>
<p align="center"><FONT COLOR="#FF0000">?????????????????</FONT>
</body>
</html>
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn, i, 1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn, i + 1, 1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
Private Sub Command1_Click()
Set objhttp = CreateObject("MSXML2.XMLHTTP")
Set xmlDoc = CreateObject("MSXML.DOMDocument")
strWebserviceURL = "http://www.csdn.net/member/logon.asp"
'设置参数及其值
strRequest = "login_name=用户名&password=密码&cookietime=0&x=42&y=10"
objhttp.open "POST", strWebserviceURL, False
'设置这个Content-Type很重要
objhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
'SOAPAction这个Header头同样可以在sample中找到
objhttp.setRequestHeader "SOAPAction", "http://tempuri.org/Add"
objhttp.setRequestHeader "Content-Length", Len(strWebserviceURL)objhttp.send (strRequest)
MsgBox bytes2BSTR(objhttp.responseBody)
'bOK = xmlDoc.Load(objhttp.responseXML)
''看看状态值
'MsgBox objhttp.Status
'MsgBox objhttp.statusText
''objHTTP.Status=200,这里就可以处理返回的xml片段了
''如果需要,可以替换返回的xml字符串当中的<和>
'If objhttp.Status = 200 Then MsgBox "Success"
'xmlStr = xmlDoc.xml
'xmlStr = Replace(xmlStr, "<", "<", 1, -1, 1)
'xmlStr = Replace(xmlStr, ">", ">", 1, -1, 1)
'
'MsgBox xmlStr
End Sub
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="Refresh" content="2;URL=/Member/Passport.asp">
<meta http-equiv="Content-Type" content="text/html" ; charset="gb2312">
<title>CSDN_Login……</title>
</head>
<body>
<br>
<p align="center"><FONT COLOR="#FF0000">正在登录,请稍候…………</FONT>
</body>
</html>
'设置这个Content-Type很重要
objhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"编码的函数如下 :Public Function URLEncode(ByVal strInput As String) As String
Dim strOutput As String
Dim intAscii As Integer
Dim i As Integer
For i = 1 To Len(strInput)
intAscii = Asc(Mid(strInput, i, 1))
If ((intAscii < 58) And (intAscii > 47)) Or _
((intAscii < 91) And (intAscii > 64)) Or _
((intAscii < 123) And (intAscii > 96)) Then
strOutput = strOutput & Chr$(intAscii)
Else
strOutput = strOutput & _
IIf(intAscii < 16, "%0", "%") & _
Trim$(Hex$(intAscii))
End If
Next
URLEncode = strOutput
End Function以下为使用:
strRequest = "login_name=" & URLEncode("用户名") & "&password=" & URLEncode"密码") & "&cookietime=0&x=42&y=10"
objhttp.setRequestHeader "Content-Length", Len(strRequest)
MsgBox bytes2BSTR(objhttp.responseBody)To MsgBox StrConv(objhttp.responseBody, vbUnicode)其实VB已经提供这种函数了,我还是用的vbs的方法,呵呵~~
这个是完整的代码,我测试过的~~
回来我干脆开个帖子专门解决xml+网络编程的问题算了~~
'Add The Reference of MSXML2.6
'Add a Command And Two TextBox On The Form:Private Sub Command1_Click()
'Add The Reference of MSXML2.6
Dim xmlhttp As New MSXML2.xmlhttp
'用下面的定义也可以的
'Dim xmlhttp As Object'Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
'设置请求的网页
Dim strWebserviceURL As StringstrWebserviceURL = "http://www.csdn.net/member/logon.asp"
'设置参数及其值
strRequest = "login_name=" & URLEncode(Trim$(Text1.Text)) & "&password=" & URLEncode(Trim$(Text2.Text)) & "&from=" & URLEncode("http://expert.csdn.net") & "&cookietime=0&x=42&y=10"xmlhttp.open "POST", strWebserviceURL, False
xmlhttp.setRequestHeader "Content-Length", Len(strRequest)
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"xmlhttp.send strRequest
If Err.Number <> 0 Then MsgBox "登录失败!": Exit Sub
Debug.Print StrConv(xmlhttp.responseBody, vbUnicode) '显示登录信息的
'看看状态值
'xmlhttp.Status=200,这里就可以处理返回的xml片段了
If xmlhttp.Status = 200 Then MsgBox "Success"
strWebserviceURL = "http://expert.csdn.net/Expert/member/MyForum.asp?typenum=2"
xmlhttp.open "GET", strWebserviceURL, False '请求一下这个网页就看到效果了,呵呵~~
xmlhttp.send
Debug.Print StrConv(xmlhttp.responseBody, vbUnicode)Set xmlhttp = NothingEnd Sub
Public Function URLEncode(ByVal strInput As String) As String
Dim strOutput As String
Dim intAscii As Integer
Dim i As Integer
For i = 1 To Len(strInput)
intAscii = Asc(Mid(strInput, i, 1))
If ((intAscii < 58) And (intAscii > 47)) Or _
((intAscii < 91) And (intAscii > 64)) Or _
((intAscii < 123) And (intAscii > 96)) Then
strOutput = strOutput & Chr$(intAscii)
Else
strOutput = strOutput & _
IIf(intAscii < 16, "%0", "%") & _
Trim$(Hex$(intAscii))
End If
Next
URLEncode = strOutput
End Function不得不感叹,这么简单的问题,csdn居然都没人回答,要不是我对这个问题比较感兴趣,估计楼主最后就要被csdn强制结帖了,晕倒~~
我没什么时间,我开个帖子,以后有什么问题到我的帖子里问~~
http://expert.csdn.net/Expert/topic/2908/2908081.xml?temp=.550564