|
-
Oct 23rd, 2006, 01:14 AM
#1
Thread Starter
Lively Member
[RESOLVED] Sending HTTP requests
GET http://www.vbforums.com/index.html HTTP/1.1
Host: www.vbforums.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
How should I go about sending http requests etc with winsock? I know they need to include a header and a GET / POST request.
-
Oct 23rd, 2006, 01:40 AM
#2
Lively Member
Re: Sending HTTP requests
WEll you need to connect to the host (in this case www.vbforums.com) and send the request, dont forget about the blank lines (vbcrlf) they are important, in the request end usually there are 2 blank lines as i remember!
And this: "Accept-Encoding: gzip,deflate" shows you will get the output data compressed with gzip/deflate, to recieve uncompressed text just do: "Accept-Encoding:".
Last edited by Jean.B; Oct 23rd, 2006 at 03:13 AM.
-
Oct 23rd, 2006, 07:30 AM
#3
Thread Starter
Lively Member
-
Oct 23rd, 2006, 08:46 AM
#4
Lively Member
Re: Sending HTTP requests
Well next you send the http request to the next page you want to go..collect cookies if they are sent, some sites checks checksum, if its wrong then it usually server sends you message back about wrong checksum.
-
Oct 24th, 2006, 04:44 AM
#5
Re: Sending HTTP requests
 Originally Posted by skankerer
Ok I got it happening but when I get the response I'm not sure how to seperate the server's response, e.g.
Recommend an exact RFC for me to read?
HTTP/1.1 200 OK
Date: Mon, 23 Oct 2006 12:29:35 GMT
Server: Apache
'PHPBBCOOKIE 
PHPBBCOOKIE 
PHPBBCOOKIE 
PHPBBCOOKIE 
Expires: 0
Cache-Control: private, post-check=0, pre-check=0, max-age=0
Pragma: no-cache
Content-Length: 111948
Connection: close
Content-Type: text/html; charset=ISO-8859-1
Thanks.
Do you mean parsing out individual things like content-length, cache-control, etc.? If so, you could use something like this:
VB Code:
Option Explicit
'Function to get the value of an HTTP variable.
'Used for parsing HTTP server responses.
Private Function GetHTTPVar(ByVal Name As String, ByVal HTTPData As String) As String
Dim lonPos As Long, lonLenName As Long
Dim strRet As String, lonLen As Long
Dim lonCrLf As Long
lonLenName = Len(Name)
lonLen = Len(HTTPData)
lonPos = InStr(1, HTTPData, Name, vbTextCompare)
If lonPos > 0 Then
lonCrLf = InStr(lonPos + 1, HTTPData, vbNewLine)
GetHTTPVar = Mid$(HTTPData, (lonPos + lonLenName), (lonCrLf - (lonPos + lonLenName)))
End If
End Function
Private Sub Form_Load()
Dim strHTTP As String
'Build some data to test with.
strHTTP = "HTTP/1.1 200 OK" & vbNewLine & _
"Date: Mon, 23 Oct 2006 12:29:35 GMT" & vbNewLine & _
"Server: Apache" & vbNewLine & _
"Expires: 0" & vbNewLine & _
"Cache-Control: private, post-check=0, pre-check=0, max-age=0" & vbNewLine & _
"Pragma: no-cache" & vbNewLine & _
"Content-Length: 111948" & vbNewLine & _
"Connection: Close" & vbNewLine & _
"Content-Type: text/html; charset=ISO-8859-1" & vbNewLine & vbNewLine
Dim strVar As String
'Get the Cache-Control variable.
strVar = GetHTTPVar("Cache-Control: ", strHTTP)
MsgBox strVar
End Sub
-
Oct 27th, 2006, 05:54 AM
#6
New Member
Re: Sending HTTP requests
Well if you want to send HTTP request to the server, the best idea would be XMLHTTP object. That would be simple to user other than going with winsock.
-
Nov 1st, 2006, 07:30 AM
#7
New Member
Re: [RESOLVED] Sending HTTP requests

Hello, I was also experimenting a little bit with HTTP and wrote this really little program.
It only requests and receives a page which will be shown unformatted in a simple TextBox. 
What was your intention to it? Mine was a code-request in another forum, where someone wanted to log himself into a html-site by a vb-program.
I suggested him to read this RFC: http://www.ietf.org/rfc/rfc2616.txt
It would be nice if you could post your code as well. Just because I'm interested into comparing it etc. . 
Here is the complete Code of it:
VB Code:
'1 TextBox: name-> txtOut
'1 TextBox: name-> txtURL
'1 CommandButton: name-> cmdGo
Option Explicit
Private InetData As String
Private URL As String
Private Sub cmdGo_Click()
txtOut.Text = ""
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Connect URL, 80
End Sub
Private Sub Form_Load()
URL = txtURL.Text
End Sub
Private Sub txtURL_Change()
URL = txtURL.Text
End Sub
Private Sub Winsock1_Connect()
Call GetWebpage(Winsock1)
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData InetData
txtOut.Text = txtOut.Text & InetData
End Sub
Public Sub GetWebpage(wsk As Winsock)
With wsk
.SendData "GET /" & " HTTP/1.1" & vbCrLf
.SendData "Accept: text/plain" & vbCrLf
.SendData "Accept-Language: en-us" & vbCrLf
'.SendData "Accept-Encoding: gzip, deflate" & vbCrLf
'.SendData "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)" & vbCrLf
.SendData "Host: " & wsk.LocalIP & vbCrLf
.SendData "Connection: Keep-Alive" & vbCrLf & vbCrLf
End With
End Sub
-
Nov 1st, 2006, 09:32 PM
#8
Re: [RESOLVED] Sending HTTP requests
 Originally Posted by DrGonzo
Hello, I was also experimenting a little bit with HTTP and wrote this really little program.
It only requests and receives a page which will be shown unformatted in a simple TextBox.
What was your intention to it? Mine was a code-request in another forum, where someone wanted to log himself into a html-site by a vb-program.
I suggested him to read this RFC: http://www.ietf.org/rfc/rfc2616.txt
It would be nice if you could post your code as well. Just because I'm interested into comparing it etc. .
Here is the complete Code of it:
VB Code:
'1 TextBox: name-> txtOut
'1 TextBox: name-> txtURL
'1 CommandButton: name-> cmdGo
Option Explicit
Private InetData As String
Private URL As String
Private Sub cmdGo_Click()
txtOut.Text = ""
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Connect URL, 80
End Sub
Private Sub Form_Load()
URL = txtURL.Text
End Sub
Private Sub txtURL_Change()
URL = txtURL.Text
End Sub
Private Sub Winsock1_Connect()
Call GetWebpage(Winsock1)
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData InetData
txtOut.Text = txtOut.Text & InetData
End Sub
Public Sub GetWebpage(wsk As Winsock)
With wsk
.SendData "GET /" & " HTTP/1.1" & vbCrLf
.SendData "Accept: text/plain" & vbCrLf
.SendData "Accept-Language: en-us" & vbCrLf
'.SendData "Accept-Encoding: gzip, deflate" & vbCrLf
'.SendData "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)" & vbCrLf
.SendData "Host: " & wsk.LocalIP & vbCrLf
.SendData "Connection: Keep-Alive" & vbCrLf & vbCrLf
End With
End Sub
I wouldn't use multiple .SendData methods like that.
Instead, build all that data into a string variable, and send it off as one packet. ie:
VB Code:
strData = "GET /" & " HTTP/1.1" & vbCrLf
strData = strData & "Accept: text/plain" & vbCrLf
'etc..
.SendData strData
strData = ""
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|