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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

POST request to ASP using wininet

Status
Not open for further replies.

misterstick

Programmer
Apr 7, 2000
633
GB
i'm trying to create a browser using wininet 5.00.2919.6305 (msie 5.01 128-bit international).<br><br>i've managed to get the GET method to work properly.<br><br>however, with forms using the POST method HttpSendRequest seems not to be adding the form data to the request, resulting in a &quot;field 1 blank&quot; error message as the return.<br><br>a quick search of the net suggests this could be because the accepting page does a redirect, but the code returned by HttpQueryInfo HTTP_QUERY_STATUS_REQUEST is 200 and not 302.<br><br>so, two questions:<br><br>1. how do i make this work?<br>2. how does wininet handle redirect requests from asp pages?<br><br>&lt;code&gt;<br>lngInetC = InternetOpen(strAppTitle, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, (0&))<br>lngInetH = InternetConnect(lngInetC, strServerName, INTERNET_DEFAULT_HTTP_PORT, vbNullString, vbNullString, INTERNET_SERVICE_HTTP, 0, 0)<br>strCBuff = strFormData ' this is in & delimited name=value pairs<br>lngCBuff = Len(strCBuff)<br>lngInetR = HttpOpenRequest(lngInetH, strMethod, strRest, &quot;HTTP/1.0&quot;, strFrom, 0, INTERNET_FLAG_RELOAD Or INTERNET_FLAG_KEEP_CONNECTION, 0)<br>' i also tried adding combinations of INTERNET_FLAG_FORMS_SUBMIT, INTERNET_FLAG_DONT_CACHE, INTERNET_FLAG_NO_AUTO_REDIRECT<br>Const cstrContent As String = &quot;Content-Type: application/x- lngInetR, cstrContent, Len(cstrContent), HTTP_ADDREQ_FLAG_REPLACE Or HTTP_ADDREQ_FLAG_ADD<br>If HttpSendRequest(lngInetR, vbNullString, 0, strCBuff, lngCBuff) &lt;&gt; 0 Then<br>&nbsp;&nbsp;lngCSize = 2048<br>&nbsp;&nbsp;strCBuff = String$(2048, vbNullChar)<br>&nbsp;&nbsp;InternetReadFile lngInetR, strCBuff, lngCSize, lngCBuff<br>&nbsp;&nbsp;strCBuff = Left$(strCBuff, lngCBuff)<br>End If<br>InternetCloseHandle lngInetC<br>&lt;/code&gt;<br>
 
after much sending of requests to a local asp page and printing the headers/content, i found out the reason i wasn't getting any response from the forms was to do with the function prototype of HttpSendRequest.<br><br>i was sending the form data as as string in the fourth parameter, with its length as the fifth parameter.<br><br>the <FONT FACE=monospace><b>Declare Function</b></font> had parameter four <b><FONT FACE=monospace>ByRef...As Any</b></font>, so what was being passed was the VB string pointer (pointer to pointer to string) and not the pointer to string it was expecting. changing the type reference of the fourth parameter to <b><FONT FACE=monospace>ByVal...As String</b></font> and making sure by putting the variable in round brackets has made it work perfectly.<br><br>i guess i was just lucky my machine didn't crash. a lot.<br><br>could i have used the <b><FONT FACE=monospace>StrPtr()</b></font> function instead?<br> <p>mr s. <;)<br><a href=mailto: > </a><br><a href= > </a><br>why does it never do what is says it does in the manual?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top