Solved

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

Posted on 2002-03-19
6
1,814 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
[X]
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
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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

738 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