arduno
Anmeldungsdatum: 12.05.2011 Beiträge: 252
|
Verfasst am: 04.12.2015, 00:40 Titel: Warum wird das nur einmal gesendet : httppost.... |
|
|
Hallo, guten Tag.
Warum wird das bitte nur einmal gesendet in der Schleife und dann geschlossen "Connection: close "?
httppost("192.168.2.105","index.html","test")
Das wurde dann gesendet:
POST /index.html HTTP/1.0
Host: 192.168.2.105
Content-Type: application/x-www-form-urlencoded
Content-Length: 4
Connection: close
test
Code: |
#Include "win/winsock2.bi"
#Include "windows.bi"
#Include "fbgfx.bi"
#include "vbcompat.bi"
Using FB
#DEFINE RECVBUFFLEN 16384
#Define newline CHR(13,10)
Sub InitWinsock Constructor
'' init winsock
DIM wsaData AS WSAData
IF( WSAStartup( MAKEWORD( 1, 1 ), @wsaData ) <> 0 ) THEN
PRINT "Error: WSAStartup failed"
END 1
END If
End SUB
SUB ExitWinsock Destructor
WSACleanup
End SUB
FUNCTION httpget(server AS STRING, path AS STRING, hadd AS STRING = "") AS STRING
DIM IP AS INTEGER
DIM ia AS in_addr
DIM s AS SOCKET
DIM hostentry AS hostent PTR
DIM sendbuffer AS STRING
DIM recvbuffer AS ZSTRING * RECVBUFFLEN+1
DIM bytes AS INTEGER
DIM sa AS sockaddr_in
DIM in AS STRING
ia.S_addr = inet_addr( server )
IF ( ia.S_addr = INADDR_NONE ) THEN
hostentry = gethostbyname( server )
IF ( hostentry = 0 ) THEN
RETURN "IP couldn't be resolved!"
END IF
IP = *CAST( INTEGER PTR, *hostentry->h_addr_list )
ELSE
IP = ia.S_addr
END IF
s = opensocket( AF_INET, SOCK_STREAM, IPPROTO_TCP )
IF( s = 0 ) THEN
RETURN "Socket couldn't be opened."
END IF
sa.sin_port = htons( 80 )
sa.sin_family = AF_INET
sa.sin_addr.S_addr = ip
IF ( connect( s, CAST( PSOCKADDR, @sa ), LEN( sa )) = SOCKET_ERROR ) THEN
closesocket( s )
RETURN "Couldn't connect to host"
END IF
sendBuffer = "GET /" + path + " HTTP/1.0" + NEWLINE + _
"Host: " + server + NEWLINE + _
"Connection: close" + NEWLINE + _
hadd + _
NEWLINE
IF( send( s, sendBuffer, LEN( sendBuffer ), 0 ) = SOCKET_ERROR ) THEN
closesocket( s )
RETURN "Couldn't send request"
END IF
DO
bytes = recv( s, recvBuffer, RECVBUFFLEN, 0 )
IF( bytes <= 0 ) THEN
EXIT DO
END IF
recvbuffer[bytes] = 0
in += recvbuffer
LOOP
shutdown( s, 2 )
closesocket( s )
RETURN in
END FUNCTION
FUNCTION httppost(server AS STRING, path AS STRING, toPost AS STRING, hadd AS STRING = "") AS STRING
DIM IP AS INTEGER
DIM ia AS in_addr
DIM s AS SOCKET
DIM hostentry AS hostent PTR
DIM sendbuffer AS STRING
DIM recvbuffer AS ZSTRING * RECVBUFFLEN+1
DIM bytes AS INTEGER
DIM sa AS sockaddr_in
DIM in AS STRING
ia.S_addr = inet_addr( server )
IF ( ia.S_addr = INADDR_NONE ) THEN
hostentry = gethostbyname( server )
IF ( hostentry = 0 ) THEN
RETURN "IP couldn't be resolved!"
END IF
IP = *CAST( INTEGER PTR, *hostentry->h_addr_list )
ELSE
IP = ia.S_addr
END IF
s = opensocket( AF_INET, SOCK_STREAM, IPPROTO_TCP )
IF( s = 0 ) THEN
RETURN "Socket couldn't be opened."
END IF
sa.sin_port = htons( 80 )
sa.sin_family = AF_INET
sa.sin_addr.S_addr = ip
IF ( connect( s, CAST( PSOCKADDR, @sa ), LEN( sa )) = SOCKET_ERROR ) THEN
closesocket( s )
RETURN "Couldn't connect to host"
END IF
sendBuffer = "POST /" + path + " HTTP/1.0" + NEWLINE + _
"Host: " + server + NEWLINE + _
"Content-Type: application/x-www-form-urlencoded" + NEWLINE + _
"Content-Length: " + STR(LEN(toPost)) + NEWLINE + _
"Connection: close" + NEWLINE + _
hadd + _
NEWLINE + _
toPost + NEWLINE
IF( send( s, sendBuffer, LEN( sendBuffer ), 0 ) = SOCKET_ERROR ) THEN
closesocket( s )
RETURN "Couldn't send request"
END IF
DO
bytes = recv( s, recvBuffer, RECVBUFFLEN, 0 )
IF( bytes <= 0 ) THEN
EXIT DO
END IF
recvbuffer[bytes] = 0
in += recvbuffer
LOOP
shutdown( s, 2 )
closesocket( s )
RETURN in
END Function
ScreenRes 400,500,32
ScreenControl SET_WINDOW_POS, 500, 40
Do
If MULTIKEY(FB.SC_ESCAPE) Then
End
EndIf
httppost("192.168.2.105","index.html","test")
Sleep 1000
Cls
Loop
End
|
Danke.
Gruss |
|