Send POST data to web server
Send POST data to web server
Hello, how to send POST data to web server?
It is necessary to fill two fields (login, password) and push the button of "login", and after logging show HTML document.
Can you show example? Thanks...
It is necessary to fill two fields (login, password) and push the button of "login", and after logging show HTML document.
Can you show example? Thanks...
http://www.purebasic.fr/english/viewtop ... highlight=
and search about FTP things
or see in "PureBasic CodeArchiv v4.0 Beta"
http://www.purebasic.fr/english/viewtop ... codearchiv
and search about FTP things
or see in "PureBasic CodeArchiv v4.0 Beta"
http://www.purebasic.fr/english/viewtop ... codearchiv
This is a program I wrote about a year ago to process data from a web-API program. Not sure if the userid and password(key) still work but you can get the idea.
Hope this helps
Slyvnr
Code: Select all
result=InitNetwork()
Debug result
If result
; these are the fields being posted for the system to call back the data
; not sure if these codes are still valid for getting data
apiUSERID.s="2196844"
apiUSERKEY.s="Xm1GcG9eVCbNoZXZApZe1Vs9FZf2qHrNpcRYOr34X4i7uEcyVc9htLeWUqvyZyem"
; web page to post to
hostpgm$="http://api.eve-online.com/account/Characters.xml.aspx?"
hostdata$="userID="+apiUSERID+"&apiKey="+apiUSERKEY
lenhostdata=Len(hostdata$)
lenhd$=Str(lenhostdata)
hostconnectionstring$=hostpgm$+hostdata$
Debug hostconnectionstring$
ConnectionID = OpenNetworkConnection("api.eve-online.com", 80)
Debug ConnectionID
If ConnectionID
; proper format
com$="POST "+hostconnectionstring$+" HTTP/1.1"+Chr(13)+Chr(10)
com$=com$+"Accept: */*"+Chr(13)+Chr(10)
com$=com$+"Accept: text/html"+Chr(13)+Chr(10)
com$=com$+"Host: "+"api.eve-online.com"+Chr(13)+Chr(10)
com$=com$+"User-Agent: Skill Parser"+Chr(13)+Chr(10)
com$=com$+"Content-Length: " + lenhd$ + Chr(13) + Chr(10)
com$=com$+Chr(13)+Chr(10)
; open the network
Res = SendNetworkData(ConnectionID,@com$,Len(com$))
; POST the request
Res = SendNetworkData(ConnectionID,@hostconnectionstring$,Len(hostconnectionstring$))
Repeat
Delay(100)
Result = NetworkClientEvent(ConnectionID)
Debug Result
Select Result
Case 2
Content$ = Space(14500)
ReceiveNetworkData(ConnectionID,@Content$,14500)
Debug Content$
Ok = 1
CloseNetworkConnection(ConnectionID)
EndSelect
Until Ok = 1
EndIf
Else
MessageRequester("Error","NO TCP/IP Stack to call",#PB_MessageRequester_Ok)
EndIf
;write the response web-page to a txt file for processing by other program.
filnum=OpenFile(#PB_Any,"c:\test.txt")
If filnum
WriteString(filnum,Content$)
EndIf
CloseFile(filnum)
Slyvnr
1) when I refer to API I am referring to a specific non-Windows API that this particular company provides for accessing data from their game servers outside of the game.
2) I have no idea on secure servers (https:) as I have never tried it. As you can see from the example it is a simple http: POST. It will work depending on how the "secure" portion of https: works and whether or not you can call some .dll or as you say Windows-API that provides the encryption mechanics.
Slyvnr
2) I have no idea on secure servers (https:) as I have never tried it. As you can see from the example it is a simple http: POST. It will work depending on how the "secure" portion of https: works and whether or not you can call some .dll or as you say Windows-API that provides the encryption mechanics.
Slyvnr
Strange problem...
I refer GET request for server with browser imitation (Firefox):
After execution of this code: server will answer me page of the site (HTML code) and this code write to "C:/2.txt" file... I open this file and see size (symbols) of file: 2 920.
Why 2 920 rather 5000 — ReceiveNetworkData(Connect, @two$, 5000)???

Thanks!
I refer GET request for server with browser imitation (Firefox):
Code: Select all
InitNetwork()
Connect = OpenNetworkConnection("88.191.63.41", 80)
If Connect
two$ = "GET /index.php HTTP/1.1" + Chr(13) + Chr(10)
two$ = two$ + "Host: www.purebasic.com" + Chr(13) + Chr(10)
two$ = two$ + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.1) Gecko/20090624 Firefox/3.5" + Chr(13) + Chr(10)
two$ = two$ + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" + Chr(13) + Chr(10)
two$ = two$ + "Accept-Language: ru,en-us;q=0.7,en;q=0.3" + Chr(13) + Chr(10)
two$ = two$ + "Accept-Encoding: gzip,deflate" + Chr(13) + Chr(10)
two$ = two$ + "Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7" + Chr(13) + Chr(10)
two$ = two$ + "Keep-Alive: 300" + Chr(13) + Chr(10)
two$ = two$ + "Connection: keep-alive" + Chr(13) + Chr(10)
two$ = two$ + Chr(13) + Chr(10)
SendNetworkData(Connect, @two$, Len(two$))
two$ = ""
Debug ReceiveNetworkData(Connect, @two$, 5000)
If CreateFile(0, "C:/2.txt")
WriteString(0, two$)
EndIf
Else
End
EndIf
Why 2 920 rather 5000 — ReceiveNetworkData(Connect, @two$, 5000)???

Thanks!
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Well, what does 'Debug ReceiveNetworkData(Connect, @two$, 5000)' display in the debugger ?Phantomas wrote:After execution of this code: server will answer me page of the site (HTML code) and this code write to "C:/2.txt" file... I open this file and see size (symbols) of file: 2 920.
Why 2 920 rather 5000 — ReceiveNetworkData(Connect, @two$, 5000)???
Also, your data buffer should be at least 5000 bytes long ... You wrote 'two$ = ""' !Purebasic.chm wrote:Result = ReceiveNetworkData(Connection, *DataBuffer, DataBufferLength)
...
Receives a raw data from the specified client. This function can be used by both client and server applications.
...
The 'Result' returns the number of bytes effectively read. If 'Result' is equal to DataBufferLength, then more data is available to be read. If an error occured on the connection (link broken, connection close by the server etc.), 'Result' will be -1.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
2920.gnozal wrote:Well, what does 'Debug ReceiveNetworkData(Connect, @two$, 5000)' display in the debugger ?Phantomas wrote:After execution of this code: server will answer me page of the site (HTML code) and this code write to "C:/2.txt" file... I open this file and see size (symbols) of file: 2 920.
Why 2 920 rather 5000 — ReceiveNetworkData(Connect, @two$, 5000)???
Maybe problem is solved: server sends answer on parts, necessary to loop RecieveNetworkData. Thanks & sorry.
Loop ReceiveNetworkData
Yes you need to loop ReceiveNetworkData until no more data.
I did it in my sample code in this section
This basically waits for the network buffer to fill up so to speak. Then checks to see if it is full and if it is gets the data. I used 14,500 byte buffer size because that is how big the response should be.
Hope this helps.
Slyvnr
I did it in my sample code in this section
Code: Select all
Repeat
Delay(100)
Result = NetworkClientEvent(ConnectionID)
Debug Result
Select Result
Case 2
Content$ = Space(14500)
ReceiveNetworkData(ConnectionID,@Content$,14500)
Debug Content$
Ok = 1
CloseNetworkConnection(ConnectionID)
EndSelect
Until Ok = 1
Hope this helps.
Slyvnr
Re: Send POST data to web server
you could invoke curl for windows via the cli
Re: Send POST data to web server
Why would you wan to use an external program when you can code the desired affect yourself?
----
R Tape loading error, 0:1
R Tape loading error, 0:1
Re: Send POST data to web server
cookies. they are a big problem till you want to hand code them, the cookie-jar is a good thingie
Re: Send POST data to web server
You can try to query the URL using GetHTTPHeader().
▓▓▓▓▓▒▒▒▒▒░░░░░
Re: Send POST data to web server
try it with any public email server 
