Envoie d'infomation dans une url selon methode POST

Le
denis
Bonjour,

Je souhaite envoyer des informations en post dans une url.

Pour cela, j'ai utilis l'objet InternetExplorer et le
code suivant:

Sub ie()
Dim objie As New InternetExplorer
objie.Visible = True
objie.Navigate "http://portcal/a.asp"
End Sub

Mais cela ne fonctionne pas,

Quelqu'un pourrait-il m'aider?

Merci

Denis
Vos réponses
Gagnez chaque mois un abonnement Premium avec GNT : Inscrivez-vous !
Trier par : date / pertinence
ng
Le #14735941
Salut,

Voici du code posté par JM le 05/04/2004 permettant notamment un envoi par
POST :

Declare Function InternetOpen Lib "wininet.dll"
Alias "InternetOpenA" ( _
ByVal sAgent As String, _
ByVal lAccessType As Long, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal lFlags As Long) As Long

Declare Function InternetConnect Lib "wininet.dll"
Alias "InternetConnectA" ( _
ByVal hInternetSession As Long, _
ByVal sServerName As String, _
ByVal nServerPort As Integer, _
ByVal sUsername As String, _
ByVal sPassword As String, _
ByVal lService As Long, _
ByVal lFlags As Long, _
ByVal lContext As Long) As Long

Declare Function HttpOpenRequest Lib "wininet.dll"
Alias "HttpOpenRequestA" ( _
ByVal hHttpSession As Long, _
ByVal sVerb As String, _
ByVal sObjectName As String, _
ByVal sVersion As String, _
ByVal sReferer As String, _
ByVal something As Long, _
ByVal lFlags As Long, _
ByVal lContext As Long) As Long

Declare Function HttpSendRequest Lib "wininet.dll"
Alias "HttpSendRequestA" ( _
ByVal hHttpRequest As Long, _
ByVal sHeaders As String, _
ByVal lHeadersLength As Long, _
ByVal sOptional As String, _
ByVal lOptionalLength As Long) As Long

Declare Function InternetReadFile Lib "wininet.dll" ( _
ByVal hFile As Long, _
ByVal sBuffer As String, _
ByVal lNumBytesToRead As Long, _
lNumberOfBytesRead As Long) As Long

Declare Function HttpQueryInfo Lib "wininet.dll"
Alias "HttpQueryInfoA" ( _
ByVal hHttpRequest As Long, _
ByVal lInfoLevel As Long, _
ByRef sBuffer As Any, _
ByRef lBufferLength As Long, _
ByRef lIndex As Long) As Integer

Declare Function InternetCloseHandle Lib "wininet.dll" ( _
ByVal hInet As Long) As Integer

Const INTERNET_FLAG_SECURE = &H800000
Const INTERNET_FLAG_IGNORE_CERT_CN_INVALID = &H1000
Const INTERNET_FLAG_RELOAD = &H80000000

Const HTTP_QUERY_STATUS_CODE = 19
Const HTTP_QUERY_STATUS_TEXT = 20

Const INTERNET_SERVICE_HTTP = 3

Const INTERNET_OPEN_TYPE_PRECONFIG = 0

Const INTERNET_DEFAULT_HTTP_PORT = 80
Const INTERNET_DEFAULT_HTTPS_PORT = 443

Public Function UrlPost(stURL As String, stPostData As
String, _
stStatusCode As String, stStatusText As
String, _
Optional lgInternet As Integer INTERNET_DEFAULT_HTTP_PORT, _
Optional stUser As String = vbNullString, _
Optional stPass As String = vbNullString, _
Optional stFiltreDeb As String, _
Optional stFiltreFin As String) As String
' Cette fonction permet lire le contenu d'une URL.
' Elle permet éventuellement aussi de poster des données
sur un formulaire
' et peut fonctionner en mode HTTP et HTTPS
Dim stRead As String * 2048, lgRead As Long
Dim stLoad As String
Dim blDoLoop As Boolean
Dim hISession As Long, hIConnect As Long, hRequest As Long
Dim stUrlDeb As String, stUrlFin As String
Dim stMethod As String
Dim stPost As String
Dim lgFlags As Long, lgRep As Long

Dim i As Integer
Dim i2 As Integer
Dim stLoadFiltre As String
Dim strF As String

' Découpage de l'URL en serveur et fichier
If (InStr(1, stURL, "/") > 0) Then
'stUrlDeb = Replace(LCase$(stURL), "http://",
vbNullString)
'stUrlDeb = Replace(LCase$(stUrlDeb), "https://",
vbNullString)
stUrlDeb = stURL
stUrlFin = stUrlDeb
stUrlDeb = Left$(stUrlDeb, InStr(1, stUrlDeb, "/") - 1)
stUrlFin = Mid$(stUrlFin, InStr(1, stUrlFin, "/") + 1)
Else
stUrlDeb = stURL
stUrlFin = vbNullString
End If
' Mise au point de la méthode d'envoi
If (stPostData <> vbNullString) Then
stPost = stPostData
stMethod = "POST"
stLoad = "Content-Type: application/x-www-form-
urlencoded" & vbCrLf
Else
stPost = vbNullString
stMethod = "GET"
stLoad = vbNullString
End If
If (lgInternet = INTERNET_DEFAULT_HTTPS_PORT) Then
lgFlags = INTERNET_FLAG_SECURE Or _
INTERNET_FLAG_IGNORE_CERT_CN_INVALID
Else
lgFlags = INTERNET_FLAG_RELOAD
End If

' Mise en place de la connexion Internet
hISession = InternetOpen(stUserAgent,
INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, vbNullString, 0)
If CBool(hISession) Then
' Ouverture de la connexion internet
hIConnect = InternetConnect(hISession, _
stUrlDeb, _
lgInternet, _
stUser, _
stPass, _
INTERNET_SERVICE_HTTP, _
0, _
0)
' Préparation de l'ouverture de la page
hRequest = HttpOpenRequest(hIConnect, _
stMethod, _
stUrlFin, _
"HTTP/1.0", _
vbNullString, _
0, _
lgFlags, _
0)
' Lancement de l'URL (avec les paramètres le cas
échéant)
lgRep = HttpSendRequest(hRequest, stLoad, Len(stLoad),
stPost, Len(stPost))
' Récupération du texte/contenu de la page
blDoLoop = True
stLoad = vbNullString
Do While blDoLoop
stRead = vbNullString
blDoLoop = InternetReadFile(hRequest, stRead, Len
(stRead), lgRead)
stLoad = stLoad & Left$(stRead, lgRead)
If Not CBool(lgRead) Then blDoLoop = False
Loop

If stFiltreDeb <> "" Then
stLoadFiltre = ""
i = InStr(1, stLoad, stFiltreDeb)
While i <> 0
i2 = InStr(i, stLoad, stFiltreFin)
strF = Mid$(stLoad, i + 1, i2 - i + Len
(stFiltreFin) - 2)
stLoadFiltre = stLoadFiltre & IIf(stLoadFiltre
= "", "", vbCrLf) & strF

i = InStr(i2, stLoad, stFiltreDeb)
Wend
End If

' Code http de retour (statut)
stStatusCode = Space$(1024)
lgRead = 1024
HttpQueryInfo hRequest, HTTP_QUERY_STATUS_CODE, ByVal
stStatusCode, lgRead, 0
stStatusCode = Left$(stStatusCode, lgRead)
' Texte associé
stStatusText = Space$(1024)
lgRead = 1024
HttpQueryInfo hRequest, HTTP_QUERY_STATUS_TEXT, ByVal
stStatusText, lgRead, 0
stStatusText = Left$(stStatusText, lgRead)
End If

' Fermeture des connexions
On Error Resume Next
InternetCloseHandle hISession
InternetCloseHandle hIConnect
InternetCloseHandle hRequest
On Error GoTo 0

' Retourne le contenu de la page chargée
If stFiltreDeb <> "" Then
UrlPost = stLoadFiltre
Else
UrlPost = stLoad
End If
End Function

--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/

denis
Bonjour,

Je souhaite envoyer des informations en post dans une url.

Pour cela, j'ai utilisé l'objet InternetExplorer et le
code suivant:

Sub ie()
Dim objie As New InternetExplorer
objie.Visible = True
objie.Navigate "http://portcal/a.asp"
End Sub

Mais cela ne fonctionne pas,

Quelqu'un pourrait-il m'aider?

Merci

Denis


denis
Le #14735931
Merci,

je vais tester.

Denis


-----Message d'origine-----
Salut,

Voici du code posté par JM le 05/04/2004 permettant


notamment un envoi par
POST :

Declare Function InternetOpen Lib "wininet.dll"
Alias "InternetOpenA" ( _
ByVal sAgent As String, _
ByVal lAccessType As Long, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal lFlags As Long) As Long

Declare Function InternetConnect Lib "wininet.dll"
Alias "InternetConnectA" ( _
ByVal hInternetSession As Long, _
ByVal sServerName As String, _
ByVal nServerPort As Integer, _
ByVal sUsername As String, _
ByVal sPassword As String, _
ByVal lService As Long, _
ByVal lFlags As Long, _
ByVal lContext As Long) As Long

Declare Function HttpOpenRequest Lib "wininet.dll"
Alias "HttpOpenRequestA" ( _
ByVal hHttpSession As Long, _
ByVal sVerb As String, _
ByVal sObjectName As String, _
ByVal sVersion As String, _
ByVal sReferer As String, _
ByVal something As Long, _
ByVal lFlags As Long, _
ByVal lContext As Long) As Long

Declare Function HttpSendRequest Lib "wininet.dll"
Alias "HttpSendRequestA" ( _
ByVal hHttpRequest As Long, _
ByVal sHeaders As String, _
ByVal lHeadersLength As Long, _
ByVal sOptional As String, _
ByVal lOptionalLength As Long) As Long

Declare Function InternetReadFile Lib "wininet.dll" ( _
ByVal hFile As Long, _
ByVal sBuffer As String, _
ByVal lNumBytesToRead As Long, _
lNumberOfBytesRead As Long) As Long

Declare Function HttpQueryInfo Lib "wininet.dll"
Alias "HttpQueryInfoA" ( _
ByVal hHttpRequest As Long, _
ByVal lInfoLevel As Long, _
ByRef sBuffer As Any, _
ByRef lBufferLength As Long, _
ByRef lIndex As Long) As Integer

Declare Function InternetCloseHandle Lib "wininet.dll" ( _
ByVal hInet As Long) As Integer

Const INTERNET_FLAG_SECURE = &H800000
Const INTERNET_FLAG_IGNORE_CERT_CN_INVALID = &H1000
Const INTERNET_FLAG_RELOAD = &H80000000

Const HTTP_QUERY_STATUS_CODE = 19
Const HTTP_QUERY_STATUS_TEXT = 20

Const INTERNET_SERVICE_HTTP = 3

Const INTERNET_OPEN_TYPE_PRECONFIG = 0

Const INTERNET_DEFAULT_HTTP_PORT = 80
Const INTERNET_DEFAULT_HTTPS_PORT = 443

Public Function UrlPost(stURL As String, stPostData As
String, _
stStatusCode As String, stStatusText As
String, _
Optional lgInternet As Integer =
INTERNET_DEFAULT_HTTP_PORT, _
Optional stUser As String = vbNullString,


_
Optional stPass As String = vbNullString,


_
Optional stFiltreDeb As String, _
Optional stFiltreFin As String) As String
' Cette fonction permet lire le contenu d'une URL.
' Elle permet éventuellement aussi de poster des données
sur un formulaire
' et peut fonctionner en mode HTTP et HTTPS
Dim stRead As String * 2048, lgRead As Long
Dim stLoad As String
Dim blDoLoop As Boolean
Dim hISession As Long, hIConnect As Long, hRequest As Long
Dim stUrlDeb As String, stUrlFin As String
Dim stMethod As String
Dim stPost As String
Dim lgFlags As Long, lgRep As Long

Dim i As Integer
Dim i2 As Integer
Dim stLoadFiltre As String
Dim strF As String

' Découpage de l'URL en serveur et fichier
If (InStr(1, stURL, "/") > 0) Then
'stUrlDeb = Replace(LCase$(stURL), "http://",
vbNullString)
'stUrlDeb = Replace(LCase$(stUrlDeb), "https://",
vbNullString)
stUrlDeb = stURL
stUrlFin = stUrlDeb
stUrlDeb = Left$(stUrlDeb, InStr(1, stUrlDeb, "/") -


1)
stUrlFin = Mid$(stUrlFin, InStr(1, stUrlFin, "/") + 1)
Else
stUrlDeb = stURL
stUrlFin = vbNullString
End If
' Mise au point de la méthode d'envoi
If (stPostData <> vbNullString) Then
stPost = stPostData
stMethod = "POST"
stLoad = "Content-Type: application/x-www-form-
urlencoded" & vbCrLf
Else
stPost = vbNullString
stMethod = "GET"
stLoad = vbNullString
End If
If (lgInternet = INTERNET_DEFAULT_HTTPS_PORT) Then
lgFlags = INTERNET_FLAG_SECURE Or _
INTERNET_FLAG_IGNORE_CERT_CN_INVALID
Else
lgFlags = INTERNET_FLAG_RELOAD
End If

' Mise en place de la connexion Internet
hISession = InternetOpen(stUserAgent,
INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, vbNullString, 0)
If CBool(hISession) Then
' Ouverture de la connexion internet
hIConnect = InternetConnect(hISession, _
stUrlDeb, _
lgInternet, _
stUser, _
stPass, _
INTERNET_SERVICE_HTTP, _
0, _
0)
' Préparation de l'ouverture de la page
hRequest = HttpOpenRequest(hIConnect, _
stMethod, _
stUrlFin, _
"HTTP/1.0", _
vbNullString, _
0, _
lgFlags, _
0)
' Lancement de l'URL (avec les paramètres le cas
échéant)
lgRep = HttpSendRequest(hRequest, stLoad, Len(stLoad),
stPost, Len(stPost))
' Récupération du texte/contenu de la page
blDoLoop = True
stLoad = vbNullString
Do While blDoLoop
stRead = vbNullString
blDoLoop = InternetReadFile(hRequest, stRead, Len
(stRead), lgRead)
stLoad = stLoad & Left$(stRead, lgRead)
If Not CBool(lgRead) Then blDoLoop = False
Loop

If stFiltreDeb <> "" Then
stLoadFiltre = ""
i = InStr(1, stLoad, stFiltreDeb)
While i <> 0
i2 = InStr(i, stLoad, stFiltreFin)
strF = Mid$(stLoad, i + 1, i2 - i + Len
(stFiltreFin) - 2)
stLoadFiltre = stLoadFiltre & IIf(stLoadFiltre
= "", "", vbCrLf) & strF

i = InStr(i2, stLoad, stFiltreDeb)
Wend
End If

' Code http de retour (statut)
stStatusCode = Space$(1024)
lgRead = 1024
HttpQueryInfo hRequest, HTTP_QUERY_STATUS_CODE, ByVal
stStatusCode, lgRead, 0
stStatusCode = Left$(stStatusCode, lgRead)
' Texte associé
stStatusText = Space$(1024)
lgRead = 1024
HttpQueryInfo hRequest, HTTP_QUERY_STATUS_TEXT, ByVal
stStatusText, lgRead, 0
stStatusText = Left$(stStatusText, lgRead)
End If

' Fermeture des connexions
On Error Resume Next
InternetCloseHandle hISession
InternetCloseHandle hIConnect
InternetCloseHandle hRequest
On Error GoTo 0

' Retourne le contenu de la page chargée
If stFiltreDeb <> "" Then
UrlPost = stLoadFiltre
Else
UrlPost = stLoad
End If
End Function

--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/

denis
Bonjour,

Je souhaite envoyer des informations en post dans une




url.

Pour cela, j'ai utilisé l'objet InternetExplorer et le
code suivant:

Sub ie()
Dim objie As New InternetExplorer
objie.Visible = True
objie.Navigate "http://portcal/a.asp"
End Sub

Mais cela ne fonctionne pas,

Quelqu'un pourrait-il m'aider?

Merci

Denis




.



Publicité
Poster une réponse
Anonyme