Solved

WebBrowser.Navigate  failes to do POST request when run as NT service

Posted on 2002-03-19
6
1,780 Views
Last Modified: 2007-11-27
   This is my code for uploading file using WebComponent:
    This code works fine when I run it as a standard EXE.
    However, when I made an NT service running under "Local System" account, this code stopped working.
    The call to Navigate is successfull, yet no data send with the POST request arrives on the server side. Essentially, my POST request becomes an HTTP GET request.
=========================================================

    Dim sWebServerResponse As String
    Dim PostData() As Byte, sPostData As String
    Dim vPostData As Variant
   
    UploadFile = False
           
     ' This is required when making an HTTP POST request by calling Navigate and passing URL-encoded PostData
    ' sPostData contains URL-encoded data from the file
    sPostData = UrlEncodeFile(sInFileName, sOutErrMsg)
   
    ' This is required when making an HTTP POST request by calling Navigate and passing URL-encoded PostData    
    PostData = StrConv(sPostData, vbFromUnicode)
    vPostData = PostData
   
    If WB.Busy Then
        WB.Stop
    End If
   
 lFlags = eNavNoHistory Or eNavNoReadFromCache
sHeaders = "Content-Type: application/x-www-form-urlencoded" & vbCrLf
sInTargetFrame = ""
sURL = "http://localhost/FileUpload/FileUpload.asp?Database=XXX&UserId=ZZZ&Passwrod=YYY"
    ' Does not work when ivoked by NT service
    WB.Navigate sURL, lFlags , sInTargetFrame, vPostData, sInHeaders
    m_FileUploadDone = False    
    ' m_FileUploadDone is set by the event handler
    ' each VB form that has a WebBrowser control implements DocumentComplete
    Do While Not m_FileUploadDone
        If DateDiff("s", dtStart, Now) > dInTransferTimeout Then
            WB.Stop
            DoEvents
            m_FileUploadDone = True
            sOutErrMsg = "PROBLEM: Upload timed out."
            Exit Function
        End If
        DoEvents
    Loop
    sWebServerResponse = WB.Document.Body.innerHTML
0
Comment
Question by:Umka
6 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6880935
hearing...
0
 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6884830
<me too - listening, that is>

Is there any reason you are using the webbrowser instead of one of the lower-level APIs?  Search for WinInet on msdn.microsoft.com if you don't know what I mean...
0
 

Author Comment

by:Umka
ID: 6885648
The reason to use WebBrowser :

To avoid any complex coding to take care of firewall issues
, proxy settings, etc.
It's all easily can be configured using WebBrowser component.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Accepted Solution

by:
anthony_glenwright earned 50 total points
ID: 6887182
If you don't need to support Windows 98 (which I'm guessing you don't), try the ServerXMLHTTP object.  You don't have to be using XML to use it, I have used it's baby brother (XMLHTTP) to download EXE files from a web server.  Is *is* inside MSXML though, so you need the MSXML parser (v4) from msdn.microsoft.com/xml

http://msdn.microsoft.com/library/en-us/xmlsdk/htm/xml_obj_iserverxmlhttprequest_7zlc.asp?frame=true

Your code will go something like this:
Dim intFile As Integer
Dim strPath As String
Dim xmlUpgradeFile As MSXML2.XMLHTTPServer

strPath = "http://somewhere.com/files/thing.xyz"

Set xmlUpgradeFile = New MSXML2.XMLHTTPServer
xmlUpgradeFile.open "GET", strPath, False, "", ""
       
xmlUpgradeFile.send
     
If xmlUpgradeFile.Status = 200 Then
  intFile = FreeFile
       
  strTemp = Space(255)
  GetTempPath Len(strTemp), strTemp
  strTemp = Split(strTemp, Chr$(0))(0)
       
  Open "C;\temp\"& Split(strPath, "/")(UBound(Split(strPath, "/"))) For Output As intFile
  Print #intFile, StrConv(xmlUpgradeFile.responseBody, vbUnicode)
  Close intFile
End if

The benefit (and the reason I'm suggesting it in your case) of the XMLHTTPServer object over the Webbrowser is that it was specifically written for server applications.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7634172
Hi Umka,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept anthony_glenwright's comment(s) as an answer.

Umka, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:kodiakbear
ID: 7666028
Moving to the paq

kb
Experts Exchange Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now