Link to home
Start Free TrialLog in
Avatar of Leandro
Leandro

asked on

How to use Webbrowser and POST

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
Avatar of roverm
roverm
Flag of Netherlands image

Why don't you use the INet control (Microsoft Internet Controls - shdocvw.oca) ?

Then the code would be:

oInetControl.Execute "https://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
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
Avatar of Leandro
Leandro

ASKER

 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.
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
Avatar of Richie_Simonetti
hearing... how to it ends?
Hi Richie, what do you mean ? "how to it ends" Mark
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!
Richie:ROTFLMAOPIMP!
Avatar of Leandro

ASKER

 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.
But the INet control "reports" progress too! In the StateChanged event you've got 12 steps. Can't you use that ?
Avatar of Leandro

ASKER

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.
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 ?
server stores the page in somewhere before send it to you?
Avatar of Leandro

ASKER

 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.
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
Avatar of Leandro

ASKER

Thank you very mucth, it was really a mistake, but the problem is still ocurring. The variables return NULL.
ASKER CERTIFIED SOLUTION
Avatar of roverm
roverm
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Leandro

ASKER

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.
Avatar of Leandro

ASKER

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.
k, glad your problem is solved!

Thanks for the points.

D'Mzzl!
RoverM
btw: You are correct, the questionmark is only nessacary if you type the url in the addressbar or do a window.navigate from script.
Avatar of Leandro

ASKER

You're welcome, thanks for the help...