Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2002-03-19
6
1,799 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
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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Validating VB6 Function 19 65
Macro Excel - Multiple If conditions 2 78
VBA - If Bookmark = "XXBOOKMARKXX" then 15 40
Collapse and expand table in Word 2010 2 27
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

790 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