-
Re: Winsock: Making HTTP POST/GET Requests
URL Encode function is inadequate for UTF8 sybols/chars like Turkish and Chines and Arabic words. I have a resolution
Example:
Code:
Print "ABcdığü !+"
Print URLEncode("ABcdığü !+")
Print URLEncode2("ABcdığü !+")
Result
Code:
ABcdığü !+
ABcd%FD%F0%FC%20%21%2B
ABcd%C4%B1%C4%9F%C3%BC%20%21%2B
General Declaratetions
Code:
Private Declare Function WideCharToMultiByte Lib "kernel32" ( _
ByVal CodePage As Long, ByVal dwFlags As Long, _
lpWideCharStr As Any, ByVal cchWideChar As Long, _
lpMultiByteStr As Any, ByVal cchMultiByte As Long, _
ByVal lpDefaultChar As Long, lpUsedDefaultChar As Long) As Long
Modul
Code:
Public Function URLEncode2(ByRef Text As String) As String
Dim UTF8Bytes() As Byte
Dim lngA As Long, strChar As String
For lngA = 1 To Len(Text)
strChar = Mid$(Text, lngA, 1)
If strChar Like "[A-Za-z0-9]" Then
Else
If strChar = "=" Then
Else
W2UTF8 strChar, UTF8Bytes
strChar = HexEncode(UTF8Bytes)
End If
End If
URLEncode2 = URLEncode2 & strChar
Next lngA
End Function
Function W2UTF8(W As String, UTF8() As Byte) As Long
Dim Bytes&
If LenB(W) = 0 Then Exit Function
ReDim UTF8(LenB(W) + 16)
Bytes = WideCharToMultiByte(65001, 0, ByVal StrPtr(W), Len(W), _
UTF8(0), UBound(UTF8), 0, ByVal 0&)
ReDim Preserve UTF8(Bytes - 1)
W2UTF8 = Bytes
End Function
Function HexEncode(B() As Byte)
Dim i&, HexArr() As String
ReDim HexArr(UBound(B))
For i = 0 To UBound(B)
HexArr(i) = Right$("0" & Hex$(B(i)), 2)
Next i
HexEncode = "%" & Join(HexArr, "%")
End Function
And i thing we dont need "blnConnected" for checking connection/closed etc. Winsock.state have a state parameter for it:
WinSock.State = sckClosed = 0
WinSock.State = sckOpen = 1
WinSock.State = sckListening = 2
WinSock.State = sckConnectionPending = 3
WinSock.State = sckResolvingHost = 4
WinSock.State = sckHostResolved = 5
WinSock.State = sckConnecting = 6
WinSock.State = sckConnected = 7
WinSock.State = sckClosing = 8
WinSock.State = sckError = 9
Example:
Waiting Close connection before new connection:
Code:
Do Until winsock.State = 0
DoEvents
Loop
-
Re: Winsock: Making HTTP POST/GET Requests
How can I use to send utf-8 value request to http ?
The php page give me the result of variable I sent as ???
-
Re: Winsock: Making HTTP POST/GET Requests
@naruponk
Im sory i cant understand, what do u want clearly. This UTF-8 function can URL encoding for unicode strings like UTF-8 Russian or Greak or Turkish words.
-
Re: Winsock: Making HTTP POST/GET Requests
Can someone please help me do this exact thing but with multiple urls?? My vb is poor.
-
Re: Winsock: Making HTTP POST/GET Requests
Some one can upgrade this code to vb 2010? If yes it will be very helpfull!
-
Re: Winsock: Making HTTP POST/GET Requests
Quote:
Originally Posted by
romanos8
Some one can upgrade this code to vb 2010? If yes it will be very helpfull!
It would probably be better if you rewrite it for use with Visual Basic .NET.
-
Re: Winsock: Making HTTP POST/GET Requests
hello!
how to post a username and password via vb then open the url on firefox?
for example
on my vb program
there are username and password textbox
then i enter
when i click the command button ,
it go to the website with my username and password and the url
-
Re: Winsock: Making HTTP POST/GET Requests
Hello.
Are you still out there to maybe possibly help me with this? Thanks!
-
Re: Winsock: Making HTTP POST/GET Requests
I modified this app a bit to simplify it but I'm getting some errors. When I try the "Send" command button a second time, "Invalid Operation at Current State" error occurs.
I am also having timeout problems sending multiple requests. The service is not recording data sent continuosly, hitting the "send" button. I think it has something to do with Winsock and not the service.
Would someone mind helping me? Thanks!
Option Explicit
' we set this to true whil a connection is established
Private blnConnected As Boolean
Dim Transaction_Num As String
Dim customer As String
Dim Location As String
Dim Weight As String
Dim Sort_Class As String
Dim ppp As Variant
Private Sub cmdSend_Click()
Dim strMethod As String
Dim strData As String
Dim strPostData As String
Dim strHeaders As String
Dim strHTTP As String
Dim X As Integer
Dim tmp As Integer
Dim Transaction_NumInt As Integer
Dim thestring As String
blnConnected = False
strPostData = ""
strHeaders = ""
If blnConnected Then Exit Sub
'"GET
'For all loads: http://ics.etechsystems.com:3000/col..._loads_on_belt (test) or http://192.168.0.21:3000/colmac/current_loads_on_belt (on site)
'To query a single load: http:// ics.etechsystems.com:3000/colmac/get_load/x (test) or http:// 192.168.0.21:3000/colmac/get_load/x (on site)
'For this service the x should be replaced with the tranaction_number you would like to find.
' txtUrl.Text = "http://ics.etechsystems.com:3000/colmac/current_loads_on_belt"
' txtUrl.Text = "http://ics.etechsystems.com:3000/colmac/get_load/1"
'POST
'For posting a load during a Colmac dump on belt: http://ics.etechsystems.com:3000/colmac/new_load on site: http://192.168.0.21:3000/colmac/new_load
' configure winsock
winsock.Protocol = sckTCPProtocol
winsock.RemoteHost = "ics.etechsystems.com"
winsock.RemotePort = 3000
strMethod = "POST"
' build encoded data the data is url encoded in the form
strData = ""
strHTTP = strMethod & " " & "/colmac/new_load" & " HTTP/1.1" & vbCrLf
strHTTP = strHTTP & "Host: " & "ics.etechsystems.com" & vbCrLf
Transaction_Num = 304
Transaction_NumInt = Val(Transaction_Num)
Transaction_Num = str(Transaction_NumInt)
customer = "5"
Location = "2"
Weight = "3"
Sort_Class = "4"
'- See above: Entered the URL http://ics.etechsystems.com:3000/colmac/new_load
strPostData = strPostData & "<new_load>" & vbCrLf
strPostData = strPostData & "<transaction_number>" & Transaction_Num & "</transaction_number>" & vbCrLf
strPostData = strPostData & "<customer>" & customer & "</customer>" & vbCrLf
strPostData = strPostData & "<location>" & Location & "</location>" & vbCrLf
strPostData = strPostData & "<weight>" & Weight & "</weight>" & vbCrLf
strPostData = strPostData & "<sort_class>" & Sort_Class & "</sort_class>" & vbCrLf
strPostData = strPostData & "</new_load>" & vbCrLf
strHeaders = "Content-Type:text/xml" & vbCrLf & _
"Content-Length:" & Len(strPostData) & vbCrLf
strHTTP = strHTTP & strHeaders
strHTTP = strHTTP & vbCrLf
strHTTP = strHTTP & strPostData
txtRequest.Text = strHTTP
winsock.Connect
' wait for a connection
While Not blnConnected
DoEvents
Wend
' send the HTTP request
winsock.SendData strHTTP
thestring = "C:\Program Files\Internet Explorer\IEXPLORE.EXE http://ics.etechsystems.com:3000/colmac/get_load/" + Transaction_Num
Shell thestring
txtResponse = "Transaction Number: " + Transaction_Num
Transaction_Num = str(Transaction_NumInt + 1)
End Sub
Sub winsock_Connect()
blnConnected = True
End Sub
-
Re: Winsock: Making HTTP POST/GET Requests
help me
i wont to mack my forum poster in vb6 with winsock tool.
i login the vb forum with this code :thumb:
Code:
Private Sub CommandLogin_Click()
Dim Packet As String
Dim Post As String
Post = "vb_login_username=" & Txtuser & "&vb_login_password=" & Txtpass & "&s=&securitytoken=guest&do=login"
Packet = "POST /login.php?do=login HTTP/1.1" & vbNewLine
Packet = Packet & "Host: www.absba.org" & vbNewLine
Packet = Packet & "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20100101 Firefox/16.0" & vbNewLine
Packet = Packet & "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & vbNewLine
Packet = Packet & "Accept-Language: ar,en-us;q=0.7,en;q=0.3" & vbNewLine
Packet = Packet & "Connection: keep -alive" & vbNewLine
Packet = Packet & "Content-Type: application/x-www-form-urlencoded" & vbNewLine
Packet = Packet & "Content-Length: " & Len(Post) & vbNewLine & vbNewLine & Post
If Winsock.State = 7 Then Winsock.SendData (Packet)
End Sub
but i cant post my Thread by this code :down:
Code:
Private Sub CommandNewThread_Click()
Dim Packet As String
Dim Post As String
Post = "subject=" & Text1 & "&message=" & Text2 & "&wysiwyg=1&iconid=0&f=29&do=postthread&posthash=&poststarttime=&loggedinuser=1026648&sbutton=&parseurl=1&emailupdate=1"
Packet = "POST /newthread.php?do=postthread&f=2 HTTP/1.1" & vbNewLine
Packet = Packet & "Host: www.absba.org" & vbNewLine
Packet = Packet & "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20100101 Firefox/16.0" & vbNewLine
Packet = Packet & "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" & vbNewLine
Packet = Packet & "Accept-Language: ar,en-us;q=0.7,en;q=0.3" & vbNewLine
Packet = Packet & "Connection: keep -alive" & vbNewLine
Packet = Packet & "Content-Type: application/x-www-form-urlencoded" & vbNewLine
Packet = Packet & "Content-Length: " & Len(Post) & vbNewLine & vbNewLine & Post
If Winsock.State = 7 Then Winsock.SendData (Packet)
thes is the code of http headerrs..
Code:
http://www.absba.org/newthread.php?do=postthread&f=29
POST /newthread.php?do=postthread&f=29 HTTP/1.1
Host: www.absba.org
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20100101 Firefox/16.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ar,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://www.absba.org/newthread.php?do=newthread&f=29
Cookie: bbsessionhash=U-MUbRgiFfdH8CrOlwP67lq8GJKqM3Igc3oDs41kOa8aj4L2gWVKP6yX55dmVNYC; bblastvisit=8dzKEZexLzFgjulJQXO19QSy8xlkBYQ1bsbsuTIiuL0.; bblastactivity=74eMV7PnXeHIAPCBvldA_77lSqVIMSJZ18_d8uexO6M.; __utma=208997954.766644000.1327287630.1327287630.1327287630.1; __utmb=208997954.38.9.1327289126285; __utmc=208997954; __utmz=208997954.1327287630.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); bbforum_view=31_pQ9K5OkHVqpcq_zo8DPYvSjON3yJtS4cq7vlvPh9a-EH1BAmRpPglx5HoPV4KvZo1jbIs0k8L17X2oTEYV4HVb46vM4t2eg-SaFPoEQQ.; bbthread_lastview=tXnsL_aOuY40KNzY0xiOHDG35S0hJQuFQv-XiI1XgBVW0h3NcbP2FwFUDSfvqXtbBIsnOrJpwh7_sRJpF_wHuUWfHDA02Hi0olO9oFk_YPQGzQTtXo_LJRGQtBzCclD2
Content-Type: application/x-www-form-urlencoded
Content-Length: 278
subject=test1&message=test2%3Cbr%3E&wysiwyg=1&iconid=0&s=&securitytoken=1351778534-c987b6ae1f3b93bd32c000d06b175a34ce3972e6&f=29&do=postthread&posthash=&poststarttime=&loggedinuser=1026648&sbutton=%C7%DA%CA%E3%CF+%C7%E1%E3%E6%D6%E6%DA+%C7%E1%CC%CF%ED%CF&parseurl=1&emailupdate=1
this is the url
http://www.absba.org/newthread.php?do=postthread&f=29
Please help me with a simple code...:sick:
Please help me with a simple code...:sick:
Please help me with a simple code...:sick:
-
Re: Winsock: Making HTTP POST/GET Requests
-
Re: Winsock: Making HTTP POST/GET Requests
in terms of connection, which is faster? winsock or the ms winhttp 5.1?
-
Re: Winsock: Making HTTP POST/GET Requests
Quote:
Originally Posted by
jhai_salvador
in terms of connection, which is faster? winsock or the ms winhttp 5.1?
Both would ultimately be doing the same thing so none would be faster.
-
Re: Winsock: Making HTTP POST/GET Requests
Quote:
Originally Posted by
Niya
Both would ultimately be doing the same thing so none would be faster.
ohh okay, thanks
-
Re: Winsock: Making HTTP POST/GET Requests
Quote:
Originally Posted by
tony007
Many thanks for sharing this cool program with us. I tried to use your code with one of my project with involves loading url from listbox in submission variables value textbox. So i added a listbox that get populated from mysql db. I added a button so that on click it starts looping through listbox item and take each item and put it in submission variables value textbox and click send. What ever i do i can make this working with loop . I encluded the code for my click button but it never works. Could u help me fix this problem.thanks
VB Code:
' transfer all urls i loop
Private Sub Command1_Click()
Dim i As Long
For i = 0 To List2.ListCount - 1
List2.Selected(i) = True
txtVariableValue(0) = List2.List(i)
'MsgBox List2.List(i)
cmdSend_Click
Next
End Sub
just add : winsock_Close before cmdSend_Click. Let me know if it work
-
Re: Winsock: Making HTTP POST/GET Requests
alva0708, you've just replied to the post which is 10 years old... let me say it again: T-E-N years
I'm amazed by your grave-digging skills, as I haven't seen such in a while.
-
Re: Winsock: Making HTTP POST/GET Requests
Even better: consider how obsolete all of this is.
We now have quite a few helper objects in Windows we can use for making HTTP and HTTPS requests, and HTTP may be on the verge of extinction now in favor of HTTPS which this technique is useless for:
Google Chrome gets ready to mark all HTTP sites as 'bad'
-
Re: Winsock: Making HTTP POST/GET Requests
Quote:
Originally Posted by
MikiSoft
alva0708, you've just replied to the post which is 10 years old... let me say it again: T-E-N years
I'm amazed by your grave-digging skills, as I haven't seen such in a while.
:) i'm a new member of this forum
-
Re: Winsock: Making HTTP POST/GET Requests
it work for http and https. just remove http or https when you write url on the textbox. ex. https://www.google.com. you should write google.com
-
Re: Winsock: Making HTTP POST/GET Requests
Quote:
Originally Posted by
alva0708
:) i'm a new member of this forum
So what?
Quote:
Originally Posted by
alva0708
it work for http and https. just remove http or https when you write url on the textbox. ex.
https://www.google.com. you should write
google.com
No, it doesn't. That works because Google still supports HTTP connection, but soon it won't anymore.
-
Re: Winsock: Making HTTP POST/GET Requests
Suggestion removed by moderator as inappropriate.
-
Re: Winsock: Making HTTP POST/GET Requests
Quote:
Originally Posted by
bulleyes
hello!
how to post a username and password via vb then open the url on firefox?
for example
on my vb program
there are username and password textbox
then i enter
when i click the command button ,
it go to the website with my username and password and the url
check query string the site that you want to login, and then put in Submission Variables
-
Re: Winsock: Making HTTP POST/GET Requests
You still keep spamming here with answering on the old posts and even talking about the illegal stuff you do. You seriously want to get banned from here, do you?
-
Re: Winsock: Making HTTP POST/GET Requests
Do not post suggestions for doing things like this again. Activities like that are against the AUP you agreed to when you signed up.
-
Re: Winsock: Making HTTP POST/GET Requests
Quote:
Originally Posted by
alva0708
Suggestion removed by moderator as inappropriate.
Quote:
Originally Posted by
MikiSoft
You still keep spamming here with answering on the old posts and even talking about the illegal stuff you do. You seriously want to get banned from here, do you?
i'm sorry dude....so why old thread did not closed if answered the old post considered a spam ??
-
Re: Winsock: Making HTTP POST/GET Requests
never do it again....promise....cheers...
-
Re: Winsock: Making HTTP POST/GET Requests
Quote:
Originally Posted by
batori
hi,well this is a great post but i got a question
well when i do the operation with your tool i get the code,then i paste it to a text file and then rename it to .html.Then i open the file and i get the page i wanted and it says that im logged in (which is great :D ) and then automatically it takes me to my documents (which is not so important)
Then i copied the code that your tool produced
Code:
http://www.testforum.org/login.php?username=batori&password=batori&autologin=on&login=Log%2Bin
and i pasted it in here
Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Form_Load()
Call ShellExecute(0&, vbNullString, "http://www.forum.org/login.php?username=batori&password=batori&autologin=on&login=Log%2Bin", vbNullString, vbNullString, vbNormalFocus)
End Sub
then my browser open and then i get the message that the specified account does not exist??? hmmmm:(
I tought the reason could be the cookies...
because after i login i must go automatically to a new thread and post the text into a REPLY THREAD and click SUBMIT automatically...
It worked for me .Thank you so much . if i wanted to send this http request but don't wanna open the web browser is it possible? it's like kind of get request.