我有一些vb.net代码我试图在donmains.google.com上设置我的新域名的IP地址
代码如下:
Dim user As String = "MYRESOURSEID"
Dim pwd As String = "MYRESOURCEPASSWORD"
Dim host As String = "MYDOMAIN"
Dim address As String = "https://" & user & ":" & pwd & "@domains.google.com/nic/update?hostname=" & host
Dim request As HttpWebRequest = WebRequest.Create(address)
request.Method = "POST"
request.Host = "domains.google.com"
request.UserAgent = "Chrome/41.0"
request.Headers.Add("From:mkhiliger@gmail.com")
request.Headers.Add("Authorization:Basic base64-encoded-auth-string")
request.ContentLength = 0
Dim response As HttpWebResponse = request.GetResponse()
Dim dataStream As Stream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
reader.Close()
response.Close()
如果我将地址变量的值粘贴到浏览器中,它会将域设置为正常,但是当我 使用此代码,responsefromserver是badauth。
有谁知道这可能有什么问题?
答案 0 :(得分:0)
您的凭据未按开头编码 - 规格提及'注意:Google Domains使用dyndns2协议。'所以我认为你可以重新使用这个DynDNS子:
Private Sub DynUpdate(HostAddress As String, UserName As String, PassWord As String, MyWANIP As String, DynDNS_Agent As String)
Dim MySocket As New TcpClient
Dim MyStream As NetworkStream
Dim MyUpdateURL() As Byte
Dim MyReplyHTML As String
Dim BytesRead As Integer
Dim MyBuffer(4096) As Byte
Dim Offset As Integer
Dim ReturnCode, MoreInfo As String
'Dim LastUpdate As Date
Dim DynResultText As New Collections.Specialized.StringDictionary
DynResultText.Add("badsys", "The system parameter given is not valid. Valid system parameters are dyndns, statdns and custom")
DynResultText.Add("badagent", "The user agent that was sent has been blocked for not following specifications or no user agent was specified")
DynResultText.Add("badauth", "The username or password specified are incorrect")
DynResultText.Add("!donator", "An option available only to credited users (such as offline URL) was specified, but the user is not a credited user")
Try
' Init and open the socket.
MySocket.ReceiveTimeout = 20000
MySocket.Connect("members.dyndns.org", 80)
MyStream = MySocket.GetStream()
' Write the request.
MyUpdateURL = ASCII.GetBytes("GET /nic/update?hostname=" & HostAddress & "&myip=" & MyWANIP & " HTTP/1.0" & vbCrLf & "Host: members.dyndns.org" & vbCrLf & "Authorization: Basic " & System.Convert.ToBase64String(ASCII.GetBytes(UserName & ":" & PassWord)) & vbCrLf & "User-Agent: " & DynDNS_Agent & vbCrLf & vbCrLf)
MyStream.Write(MyUpdateURL, 0, MyUpdateURL.Length)
' Read the respons.
BytesRead = MyStream.Read(MyBuffer, 0, 4096)
If BytesRead > 0 Then
MyReplyHTML = ASCII.GetString(MyBuffer, 0, BytesRead)
Offset = InStr(MyReplyHTML, vbCrLf & vbCrLf)
If Offset > 0 And MyReplyHTML.Length > Offset + 4 Then
ReturnCode = Split(Mid(MyReplyHTML, Offset + 4), " ")(0)
Select Case LCase(ReturnCode)
Case "badsys", "badagent", "badauth", "notfqdn", "nohost", "numhost", "abuse"
' "Server Update failed - Action Required")
If DynResultText.ContainsKey(ReturnCode) Then MoreInfo = DynResultText.Item(ReturnCode)
'should disable further updates
Case "good" ' The update was successful, and the hostname is now updated.
Case "nochg" ' The update was unnecessary, and the hostname is unchanged.
Case "dnserr", "911"
' SeriousError
Case Else
' "Server Update failed - Return code '" & ReturnCode & "'")
End Select
End If
End If
' Clean up.
MyStream = Nothing
MySocket.Close()
MySocket = Nothing
Catch ex As Exception
' "Error Updating")
End Try
End Sub