posta från program
9 svar · 283 visningar · startad av Jymdis
Har letat upp lite kod själv men förstår inte varför jag inte får med mig informationen i arrayn? (byte e lite nytt för mig)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim web As New System.Net.WebClient()
Dim strPostData As String
Dim strHeader As String
Dim varPostData As Object
Dim bytPostData() As Byte
'Make the Post Data String
strPostData = "q=test"
'Pack the post data into a byte array
BuildPostData(bytPostData, strPostData)
'Write the byte into a variant
varPostData = bytpostdata
web.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
'Post the data
web.UploadData("http://www.google.com", varPostData)
End Sub
Private Sub BuildPostData(ByVal ByteArray() As Byte, ByVal strPostData As String)
Dim intNewBytes As Integer
Dim strCH As String
Dim i As Integer
intNewBytes = Len(strPostData) - 1
If intNewBytes < 0 Then
Exit Sub
End If
ReDim ByteArray(intNewBytes)
For i = 0 To intNewBytes
strCH = Mid$(strPostData, i + 1, 1)
If strCH = Space(1) Then
strCH = "+"
End If
ByteArray(i) = Asc(strCH)
Next
Return
End Sub
bytPostData blir alltså tom.
Därför att du skickar Arrayen ByVal. Om du använder ByRef ska du se att det går bättre.
Private Sub BuildPostData(ByRef ByteArray() As Byte, ByVal strPostData As String)
Okej - nytt problem - jag vill ansluta till en https server med samma kod - what gives? =)
Jag har då ingen aning - har aldrig sysslat med SSL. Men jag har läst om det och givetvis så kommer jag inte på länken, men jag vill minnas att det var någonstans på https://www.codeproject.com
Nån som vet cerfikat och SSL?
jag tror jag ska använda ICertificatePolicy men har ingen aning!
mm det har jag... får följande fel..
An unhandled exception of type 'System.Net.WebException' occurred in system.dll
Additional information: The underlying connection was closed: Could not establish trust relationship with remote server.
postar modifierad kod:
'Make the Post Data String
strPostData = "login=" & login.Text & "&password=" & password.Text
'Pack the post data into a byte array
BuildPostData(bytPostData, strPostData)
'Write the byte into a variant
varPostData = bytPostData
web.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
'Post the data
web.UploadData("https://10.1.1.1/cgi-bin/IP-login-cgi", varPostData)
Temporär lösning är att helt sonika installera cerfikatet via Internet Explorer en gång för att sen använda programmet å uppdatera inloggningen - MEN - det är ingen snygg lösning och om nån har nån bättre idé på hur det ska lösas så kom gärna med den.