Solved

How to use Webbrowser and POST

Posted on 2002-04-27
23
154 Views
Last Modified: 2010-05-02
I have to send SQl Server login information to an ASP page that returns an HTML report to a Webbrowser control in my application. So I do it from the Webbrowser by POST, using the code below to send it, I can get the number of bytes sent using Request.ServerVariables("CONTENT_LENGTH") but when I try to get the variables using Request.QueryString("usr") or Request.Form("usr") they do not exist, could anyone help me please. Thank you and sorry for my poor english. The code is :

Public Sub OpenReport(sPath As String, sPost As String, sHeader As String)
    'Ex.
    ' sPath = url
    ' sPost = "pwd=passhere&usr=leandro"
    ' sHeader = "Content-Type: application/x-www-form-urlencoded" & vbCrLf
    Dim bPost() As Byte
    ReDim bPost(Len(sPost))
    bPost = StrConv(sPost, vbFromUnicode)
    '
    Web.Navigate sPath, 14, vbEmpty, bPost, sHeader
    '...
End Sub
0
Comment
Question by:Leandro
  • 11
  • 8
  • 4
23 Comments
 
LVL 12

Expert Comment

by:roverm
ID: 6973124
Why don't you use the INet control (Microsoft Internet Controls - shdocvw.oca) ?

Then the code would be:

oInetControl.Execute "www.experts-exchange.com/jsp/memberLogin.jsp", "POST", "loginMemberName=" & sMemberID & _
                "&loginPassword=" & sPassword, _
                "Content-Type: application/x-www-form-urlencoded"

Where sMemberID is the member to login and sPassword is the password.

D'Mzzl!
RoverM
0
 
LVL 12

Expert Comment

by:roverm
ID: 6973125
btw:You can use the oInetControl_StateChanged event to monitor the progress since there is nothing visible when you use the INet control.
But it's way faster than the webbrowser! ;-)

D'Mzzl!
RoverM
0
 

Author Comment

by:Leandro
ID: 6973401
 Ok, but the problem is that I never used Inet Control and I noticed that it does not have a graphical interface to show the report to the user. Would I have to save a temporary document and then open it in the WebBrowser, or there is another way to do it ?

  Anyway, thank you.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 12

Expert Comment

by:roverm
ID: 6973714
Nope, first save it, then show it in the webbrowser control.
But that still would be faster.

The INet control is very well documented in the MSDN Library, but if you don't have it I could build you an example. Just say so then.

D'Mzzl!
RoverM
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6973770
hearing... how to it ends?
0
 
LVL 12

Expert Comment

by:roverm
ID: 6973816
Hi Richie, what do you mean ? "how to it ends" Mark
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6974480
I would like to know how it will ends...
I am a gentleman, you know, so i will wait until you post an answer, if you would be stooped, i could try by myself...
;)
Cheers to both!
0
 
LVL 12

Expert Comment

by:roverm
ID: 6974593
Richie:ROTFLMAOPIMP!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6975142
:O
0
 

Author Comment

by:Leandro
ID: 6977163
 The only problem with this solution is that, in some cases my app calls long running queries and I'm gonna show some response to the user. Like a progressbar or returning the document with Response.Flush.
  This calls are very mutable, so I can't preview how mutch time It will take to execute them, this eliminates the posibility of making a fake progressbar.
  So, I think that although the INet can call the page, it will be not a good solution for this specific kind of report.
  Thanks for the comments.
0
 
LVL 12

Expert Comment

by:roverm
ID: 6977377
But the INet control "reports" progress too! In the StateChanged event you've got 12 steps. Can't you use that ?
0
 

Author Comment

by:Leandro
ID: 6977584
Yes, I know that, but this progress won't consider the real progress based on the Loop that generates the table, if the table has, for example 300 lines, the INet control has no way to know it, so it can't report the real progress, neighter I could know how many lines It will return, that's why I said that I can't fake the progressbar, it's very impredictable.
0
 
LVL 12

Expert Comment

by:roverm
ID: 6977882
That's true, but a *real* website doesn't "know" that either. The generation of that table will be done at the server. The page doesn't send a "how big am I" signal to the browser as well.

Can't you deliver the nessacary data not via another way ?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6977951
server stores the page in somewhere before send it to you?
0
 

Author Comment

by:Leandro
ID: 6978275
 No Richie, the page is not stored anywhere, and roverm, I am not making a website, it's an application with html data reports, but also a website can show the progress with a progress bar control I've got, or I can fire Response.Flush eatch 10 or 20 lines.
  To report is made by sending the Query, the login information and other parameters to an asp page that executes the query (not pre-defined) into SQL Server, and returns a table (with no pre-defined columns, nor size), then I get the returned table properties and fill the html table, this table can have 1, 10, 100 or 500 lines depending on the requested report.
  Thanks again.
0
 
LVL 12

Expert Comment

by:roverm
ID: 6978356
Just occured to me in your original coding:
The parameters aren't passed correctly.

Maybe just a typo here ?

You wrote:
sPost = "pwd=passhere&usr=leandro"

While it should be:
sPost = "?pwd=passhere&usr=leandro"

See the questionmark as the first character ?

D'Mzzl!
RoverM
0
 

Author Comment

by:Leandro
ID: 6978552
Thank you very mucth, it was really a mistake, but the problem is still ocurring. The variables return NULL.
0
 
LVL 12

Accepted Solution

by:
roverm earned 150 total points
ID: 6978647
If you build a simple HTML or ASP page, which submits the data to that page, will the variables then show up ?

Like:

<html>
<body>
<form action=myaction.asp method=post>
<input type=text id=usr value="USERNAME">
<input type=text id=password value="PASSWORD">
<input type=submit id=bt_submit value="Submit"
</form>
</body>
</html>

D'Mzzl!
RoverM
0
 

Author Comment

by:Leandro
ID: 6980331
No the variables didn't show up, the problem was that the Request.Form("zzz") does not return a string, so it's necessary to type (Request.Form("zzz")) to convert since there is no implicit conversion.
And about putting a "?" at the start of the POST string, it does not work, the string must be "pwd=xxx&usr=yyy".
Anyway, thank you, although you didn't give me the explicit answer, your comments helped me in finding the answers. So, I will accept your comments as answer, thank you.
0
 

Author Comment

by:Leandro
ID: 6980337
No the variables didn't show up, the problem was that the Request.Form("zzz") does not return a string,
so it's necessary to type (Request.Form("zzz")) to convert since there is no implicit conversion.
And about putting a "?" at the start of the POST string, it does not work, the string must be "pwd=xxx&usr=yyy".
Anyway, thank you, although you didn't give me the explicit answer, your comments helped me in finding
the answers. So, I will accept your comments as answer, thank you.
0
 
LVL 12

Expert Comment

by:roverm
ID: 6980786
k, glad your problem is solved!

Thanks for the points.

D'Mzzl!
RoverM
0
 
LVL 12

Expert Comment

by:roverm
ID: 6980799
btw: You are correct, the questionmark is only nessacary if you type the url in the addressbar or do a window.navigate from script.
0
 

Author Comment

by:Leandro
ID: 6981393
You're welcome, thanks for the help...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question