Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

http Post request/response 2

Status
Not open for further replies.

CharlesFS

Technical User
Dec 14, 2008
39
BR
Guys, i need a way to make this request(html code(post method)) and get all links from the response page and insert the links in a ms access table. i use Ms access 2007 but i have a lot of results in google finding by "http post method vb" but i cant make the code work please guys help!!

The request code:
<HTML>
<head>
<title>Download</title>
</head>
<form target="CVM" action=" method="post">
<p>Login: <input type="text" name="txpLogin" value="xxx"></p>
<p>Pass: <input type="text" name="txpSenha" value="xxx" ></p>
<p>Date Pesquisa: <input type="text" name="txpData" value="01/12/2008" ></p>
<p>Hrs: <input type="text" name="txpHora" value="00:00" ></p>
<p>Tip: <input type="text" name="txpDocumento" value="ITR" ></p>
<p>subjectview: <input type="text" name="txpAssuntoIPE" value="NAO" ></p>
<input type="image" src="blank" name="submit" alt="RUN" />
</form>
<p>
</html>


Runing this, the site response are xml page.
Real sample of response page:

<?xml version="1.0" encoding="ISO-8859-1"?>
- <Download DataSolicitada="01/12/2008 00:00"TipoDocumento="ITR" DataConsulta="06/01/2009 09:22">

<Link url=" Doc="ITT" ccv="11975" DataRef="30/09/2008" FrmDtRef="dd/mm/aaaa" Sit="Lib" />
<Link url=" Doc="ITT" ccv="11855"

DataRef="30/09/2008" FrmDtRef="dd/mm/aaaa"
Sit="Lib" />

</Download>


Waiting help
Charles F.
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
This:

Sub AIU()
Dim objSrvHTTP, strXML, objXML, raiz, i, channel, itens
Dim objXML2 As DOMDocument

Set objXML = CreateObject("Msxml2.serverXMLHTTP.4.0")
send_data = "objXML.Open "POST", send_data, False
objXML.send

Set objXML2 = New DOMDocument
objXML2.LoadXML objXML.responseText
objXML2.Save "c:\test.xml"

'If you want better structured XML, use this code
txtXML = objXML2.XML
End Sub


but the post method is not working because the xml generated show "incorrect login".
 
I have some code for doing similar and will post when I get home, but I think the issue here might be that although it looks like you need to put in your login and password into the url you need to do

And look in the html for that page and you will see the fields there for login and password. As I remember you need to submit an array with the field names and an array with the field values.
 
Mightyginger thanks for the post!
waiting your holy codes :)
 
God, send me the code!
Or make my code work!!!

msn: r4v3r
. @
. bk.ru

 
This is the function I have been using with an example sub and website. Check the source on the that web address and you'll see I've basically set values for each of the names on the form and submitted it. Hopefully this should get you on the right track. Then you just need to parse the HTML you get back.


Sub test()
Dim htmlCode As String
Dim formNamesArray() As String
Dim formValuesArray() As String

ReDim formNamesArray(3)
ReDim formValuesArray(3)

formValuesArray(0) = "0#255"
formValuesArray(1) = "all"
formValuesArray(2) = "1000.1255#1000.1255"
formValuesArray(3) = "0#"

formNamesArray(0) = "bedrooms"
formNamesArray(1) = "daterangestart"
formNamesArray(2) = "type"
formNamesArray(3) = "area"
htmlCode = ReturnHTMLUsingGET(" formNamesArray, formValuesArray, "searchform")
End Sub

Function ReturnHTMLUsingGET(ByVal webAddress As String, inputNames As Variant, ByVal inputValues As Variant, ByVal formName As String)
Dim DownloadWebsiteCode As Variant
Dim i As Integer
Dim IE As InternetExplorer, URL As String, HTMLDoc As Object

Set IE = New InternetExplorer
URL = webAddress
IE.Navigate URL
IE.Visible = False

Do While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop

Set HTMLDoc = IE.Document
'Fill in the form
i = LBound(inputNames)
Do Until i = UBound(inputNames) + 1
HTMLDoc.getElementById(inputNames(i)).Value = inputValues(i)
i = i + 1
Loop


'Submit form
HTMLDoc.getElementById(formName).submit
'Wait for the response
Do While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop

ReturnHTMLUsingGET = HTMLDoc.body.innerHTML
IE.Quit
End Function
 
THANK you Mightyginger

Now the code work. The response of post request i send to a .txt file. The .txt file content:

<Link url="" zzzz=""z"" z=""zzz"" zzz=""zzz"" z=""zzz"" zz=""zz"" />
<Link url="" zzzz=""z"" z=""zzz"" zzz=""zzz"" z=""zzz"" zz=""zz"" />

Now i need a code to get the links inside de .txt file...

Tanks!
 
I used the replace method to clean the file:

...
S = HTTPSessionRequest("POST", url1, data1)
filter1 = Replace(S, """", " ")
filter2 = Replace(filter1, "<Link url= ", "")
filter3 = Replace(filter, " />", "")

Dim iFile As Integer
iFile = FreeFile()
Open "C:\resposta.txt" For Output As #iFile
Write #iFile, filter3
Close #iFile
...

now i create a import spec for the txt file and run the import via vba!
 
You may shorten your code, eg:
Code:
S = HTTPSessionRequest("POST", url1, data1)
Dim iFile As Integer
iFile = FreeFile()
Open "C:\resposta.txt" For Output As #iFile
Write #iFile, Replace(Replace(Replace(S, """", "  "), "<Link url=  ", ""), "    />", "")
Close #iFile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top