Dim cookie As String
Private Function Request(page As String, host As String, Optional postData As String = vbNullString)
Dim s As String
If postData <> "" Then
s = "POST /" & page & " HTTP/1.1" & vbNewLine
Else
s = "GET /" & page & " HTTP/1.1" & vbNewLine
End If
s = s & "Host: " & host & vbNewLine
s = s & "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; es-ES; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10" & vbNewLine
s = s & "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & vbNewLine
s = s & "Accept-Language: es-es,es;q=0.8,en-us;q=0.5,en;q=0.3" & vbNewLine
s = s & "Accept -Encoding: gzip , deflate" & vbNewLine
If cookie <> "" Then s = s & "Cookie: " & cookie
s = s & "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" & vbNewLine
s = s & "Keep-Alive: 115" & vbNewLine
If postData <> "" Then
s = s & "Content-type: application/x-www-form-urlencoded" & vbNewLine
s = s & "Content-length: " & LenB(postData) & vbNewLine
End If
s = s & "Connection: close" & vbNewLine & vbNewLine & postData
Socket.SendData s
End Function
Private Sub socket_DataArrival(ByVal bytesTotal As Long)
Dim t As String
Socket.GetData t, vbString, bytesTotal
' Debug.Print t
If t Like "HTTP/1.0*" Then
If cookie = "" And (status = 2 Or status = 3) Then
'Set-Cookie: PHPSESSID=f1fa53db6eafd9cb18628e070c7a0050; expires=Mon, 18-Oct-2010 23:37:53 GMT; path=/
Dim i As Long
i = InStr(t, "Set-Cookie: ") + Len("Set-Cookie: ")
cookie = Mid$(t, i, 43)
End If
Exit Sub
End If
' Evaluar la respuesta :) del socket
End Sub
Es un extracto de un programa estilo "no-ip" utilizando CSocketPlus o CSOcketMaster (ni recuerdo cual era
). Fijate bien las cabeceras http (tuve que "disfrazarme" de Firefox porque el hosting que tengo no permite llamadas directas
)
Vos en el postData lo envias como si fuera el final de un url
dato1=valor1&dato2=valor2
Lo demas, lo dejo que lo descubras por vos mismo
En el parametro host, va solo el dominio (ej: raul338.com.ar)