Solved

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

Posted on 2002-03-19
6
1,767 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
Comment Utility
hearing...
0
 
LVL 6

Expert Comment

by:anthony_glenwright
Comment Utility
<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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 6

Accepted Solution

by:
anthony_glenwright earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Moving to the paq

kb
Experts Exchange Moderator
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

762 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

9 Experts available now in Live!

Get 1:1 Help Now