Link to home
Start Free TrialLog in
Avatar of Sara_j_11
Sara_j_11

asked on

upload text file to https site

How to upload a text file to a https site for which I have been given a username and password using VB 6.0
I use the inet in Vb 6.0 for uploading text files to ftp site. BuT dont know how to handle https://..
 also us ethe following code to ftp a file to a third party and it works.
Private Sub Command1_Click()
    Command1.Enabled = False
    'Unload Me
    'open the log file
    ff = FreeFile
    Open "C:\ftp.log" For Append As #ff
   
    sMessage = "Transferring file " & Format(Now)
    Print #ff, sMessage
   
    Inet1.URL = "ftp://55.66.22.111"
    Inet1.UserName = "myusername"
    Inet1.Password = "mypass"
   
     Inet1.Execute , "PUT C:\file_to_ftp.TXT"
    wait
    Inet1.Execute , "CLOSE"
    wait
   
    Command1.Enabled = True
    DoEvents
    'close the log file
    Close #ff
    MsgBox "FTP attempted  check Log file for status"
End Sub

Private Sub wait()
    Do While Inet1.StillExecuting
        DoEvents
    Loop
End Sub

Private Sub Command3_Click()
Hide Me
End
End Sub



Private Sub Inet1_StateChanged(ByVal State As Integer)
    Select Case State
    Case icError
        sMessage = "Error: " & _
                Inet1.ResponseCode & vbCrLf & _
                Inet1.ResponseInfo
    Case icNone
        sMessage = "None"
    Case icConnecting
        sMessage = "Connecting"
    Case icConnected
        sMessage = "Connected"
    Case icDisconnecting
        sMessage = "Disconnecting"
    Case icDisconnected
        sMessage = "Disconnected"
    Case icRequestSent
        sMessage = "Request Sent"
    Case icRequesting
        sMessage = "Requesting"
    Case icReceivingResponse
        sMessage = "Receiving Response"
    Case icRequestSent
        sMessage = "Request Sent"
    Case icResponseReceived
        sMessage = "Response Received"
    Case icResolvingHost
        sMessage = "Resolving Host"
    Case icHostResolved
        sMessage = "Host Resolved"
    Case icResponseCompleted
        sMessage = "Response Completed " & Inet1.GetChunk(1024)
    Case Else
        Debug.Print "Unknown State"
        Exit Sub
    End Select
   
    'log the message
    Print #ff, sMessage
End Sub
Avatar of amit_g
amit_g
Flag of United States of America image

http://www.vbip.com/forum/topic.asp?id=5156

Scroll down to the post

Posted by: lorengom Date: 4/26/2003 4:17:57 AM
Avatar of Sara_j_11
Sara_j_11

ASKER

I found the following code in the post  from the link that u sent.
uFile needs to be a real file name like: "C:\temp\stevesmom.cok" or somthing.
 
    Dim vHeaders As String  'the headers we need to pass
    Dim cPostData As String 'the file contents
    Dim vPost As String     'post-data argument in Inet1.execute
     
    'create a binary file for transfer cPostData gets this info
    Dim FF
    FF = FreeFile
    Open uFile For Binary As #FF
    cPostData = Space(FileLen(uFile))
    Get #FF, , cPostData
    Close #FF
 
    'Put in your headers
    vHeaders = "Content-Type: multipart/form-data; boundary=f89awenrh8f8"
    'set up your post-data
    vPost = _
    "--------------f89awenrh8f8" & vbCrLf & _
    "Content-Disposition: form-data; name=""file1""; filename=""" & uFile & "" & vbCrLf & vbCrLf & _
    cPostData & vbCrLf & _
    "--------------f89awenrh8f8--"
     
   Inet1.Execute "","http://<yoursite>/<yourfile>.asp? '_blank'>http://<yoursite>/<yourfile>.asp?", "POST", vPost, vHeaders
 
   While Inet1.StillExecuting
       'wait until Inet finishes
       DoEvents
     Wend
 

I dont understand this line:Inet1.Execute "","http://<yoursite>/<yourfile>.asp? '_blank'>http://<yoursite>/<yourfile>.asp?", "POST", vPost, vHeaders
What is the vpost, hvheader; why is it needed?
will it work for https?
I tried to use the code replacing the line:
Inet1.Execute "","http://<yoursite>/<yourfile>.asp? '_blank'>http://<yoursite>/<yourfile>.asp?", "POST", vPost, vHeaders

with Inet1.Execute "", "https://thewebsitename.gov/wfr" ' the link that was given or the third party link

But i got the error: runtime error 35755 - no remote computer is specified

Is this part of the cod ea comment - '_blank'>http://<yoursite>/<yourfile>.asp?", "POST", vPost, vHeaders
 also what is the <yourfile>.asp? in  Inet1.Execute "","http://<yoursite>/<yourfile>.asp?
ok I just changed that line of code to Inet1.Execute "https://thewebsitename.gov/wfr/myfilename.asp", "POST", vPost, vHeaders
I dont get that error anymore - but I have a username and password to that site - where can i include that in the code? when i do my f8 to do a step by step execution - this line executes - but I have no way of telling what happened ; was it successful or not?? Please advise.
vPost - is actual body that is posted. It includes the file content.
vHeaders - any headers that need to be sent along with the post

Inet1.UserName = "UserName"
Inet1.Password = "UserName"
dear expert aikimark :
I realised that i had the title as pgp for the question in that link - so I did not want experts to get mislead , becuase of my mistake - that is why I posted a different question... Sorry if that had caused any  confusion. But I really appreciate all of yours help!
Sara,

Since you can't do your transfer via FTP, I'm curious why this question exists, even if the title emphasizes the transfer over the pgp encryption.
when i do my f8 to do a step by step execution - this line executes - but I have no way of telling what happened ; was it successful or not?? Please advise.
why do we have .asp after filename ?
"https://thewebsitename.gov/wfr/myfilename.asp", "POST", vPost, vHeaders
It won't tell anything unless there is an error. That asp is the one that receives the file uploaded.
But when i went to the website and loged on using my userisd and passw manually through internet explorer, I dont see any files uploaded there  other than the one that I manually click on the browse button and choose file ; then click on the drop down box to select the folder that the file needs to be moved to and then click on upload button...
In the following line ...

"Content-Disposition: form-data; name=""file1""; filename=""" & uFile & "" & vbCrLf & vbCrLf & _

file1 should be the name of the file field in the form. Go the that website from browser. Do a view source and find

<input type="file" name="Whatever">

Use Whatever instead of file1. Also do you have to select anything else in the form page? If so you need to send that too.
I went to the link and before logging in usign username and passw , I did a view source and a search on input type:
all that I could find was: I could not find -
input type="file"

<form name="status"><input type="hidden" name="statmess" value="Please log in." /></form>


<td class="regularbold"><input type="submit" name="action" value="Login" class="button"></td>
after loggin on doing a view source on that screen - and a search on input type- i  see the following:
<form name="status"><input type="hidden" name="statmess" value="Welcome." /></form>

 <input type="hidden" name="sid" value="a483028b5b1007eead5b6c55f625b52a" /><input type="hidden" name="action" value="view" />

<tr><td colspan="2" class="labelbold">User Menu</td></tr><tr><td colspan="2"><input type="submit" name="section" value="My Files" class="sbbutton" /></td></tr><tr><td colspan="2"><input type="submit" name="section" value="Password" class="sbbutton" /></td></tr><tr><td colspan="2"><input type="submit" name="action" value="Logout" class="sbbutton" /></td></tr><tr><td colspan="2"><hr /></td></tr></form></table>

...etc but i dont see input type = "file"
expert amit_g,
I have posted follow up for ur question. if this method will not work...

I found the following information in this site from another qeustion:
Try this free component
Download Asppload from http://www.aspupload.com/" target="_blank" onclick="return openNew(this.href);">http://www.aspupload.com/


Example coding can be found in
http://www.aspupload.com/manual.html" target="_blank" onclick="return openNew(this.href);">http://www.aspupload.com/manual.html


but the code is in ASP, how can I convert that into VB?

The site is using a form validation (login page you showed means that). That means it could be using a cookie or session (that in turn uses cookie) and it would be very difficult (not impossible) to maintain the logged in status in the next page. The input type=file would be there on the next page. You can do the view source there too but to be able to post you first need to login. The UserName/Password in Inet control are used for Basis/Windows authentication not for form based authentication.
so  does that mean  the code in the link that you posted cannot be used for this type of site that uses cookie?
I can maually login to the page using given userid and password.. But UserName/Password in Inet control  cannot be used for form base authentication. What is the alternative for this?
Wil the following work (something that waas found in this site - ). But it is used to uplaod xml document and I need to upload text file..
Try this code, I had a very similar problem to you and this works fine for me - it uploads an XML file from disk to my webserver automatically whereas before the user would have to go to the web page, browse for file, and click "upload".

Note that it does not attempt to calculate the boundry values, my webserver seems to ignore the actual value of the "boundry" as long as they are present - hopefully yours will do the same :)

Also note that I am unable to test this on a HTTPS server, only on HTTP, though in theory it should work as According to Microsoft, the  MSXML2.ServerXMLHTTP object is able to make HTTPS GET and POST requests.

----------------------------------------------------------------------------------------------------------------------------------------------------------------

DECLARATIONS/SUBS/FUNCTIONS (stick in a module):
--------------------------------------------------------------------
Function ReadFile(sFilePathAndName As String) As String
    Dim sFileContents As String, oFS As Object, oTextStream As Object
    Set oFS = CreateObject("Scripting.FileSystemObject")
    If oFS.FileExists(sFilePathAndName) <> 0 Then
        Set oTextStream = oFS.OpenTextFile(sFilePathAndName,1)
        sFileContents = oTextStream.ReadAll
        oTextStream.Close
        Set oTextStream = nothing
    End if
    Set oFS = nothing
    ReadFile = sFileContents
End Function

CODE (stick this in a sub somewhere):
-------------------------------------------------
Dim content_d As Variant, content_t As Variant, xmlReq As Variant
Dim xmlHTTP As Object
Dim xmlResp As String

'### Next 3 lines are just for debugging needed later.
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate("about:blank")

content_d = "Content-Disposition: form-data; name=" & chr$(34) & "File1" & chr$(34) & "; filename=" & chr$(34) & "c:\load.xml" & chr$(34)
content_t = "Content-Type: text/xml"

xmlReq = ReadFile("c:\load.xml")
If Len(xmlReq) < 2 Then Exit Sub '### Could not read the file!

Set xmlHTTP = CreateObject("MSXML2.ServerXMLHTTP")

With xmlHTTP
    .open "POST", "https://web-server.com/upload.asp?user=MyLoginID" target="_blank" onclick="return openNew(this.href);">https://web-server.com/upload.asp?user=MyLoginID", False
    .setRequestHeader "Content-Type", "multipart/form-data; boundary=---------------------------7d411a26bd03b6"
    .send "-----------------------------7d411a26bd03b6" & vbCrLf & content_d & vbCrLf & content_t & vbCrLf & vbCrLf & xmlReq & vbCrLf & "-----------------------------7d411a26bd03b6--" & vbCrLf
    .Response.ContentType = "text/html"
    xmlResp = .ResponseText
End With

Set xmlHTTP = Nothing

'### Next 4 lines just display the server's response in an IE window, for debugging!
IE.Visible = True
IE.Document.Open
IE.Document.Write(xmlResp)
IE.Document.Close

----------------------------------------------------------------------------------------------------------------------------------------------------------------
 
Comment from PODJOS
Date: 06/08/2004 05:14AM PDT
 Author Comment  


I say just fantastic, it works fine

i have changed just these lines :

Set xmlHTTP = CreateObject("MSXML2.ServerXMLHTTP") --> changed to Dim xmlHTTp as new msxml2.serv...
.open "POST", "https://web-server.com/upload.asp?user=MyLoginID" target="_blank" onclick="return openNew(this.href);">https://web-server.com/upload.asp?user=MyLoginID", False --> after false,Username,Password
.response.contenttype --> striked

all that I could find afetr I manually logged on to site- did a view source and searched on "file" was as follows:
 <input class="regular" type="file" name="file" class="button"/>&nbsp;</td>
could not find input type = "file"
Does the site offer save the login info so that you don't have to login for a certain time period once you log in? If yes, you could let the user of application login once and then form that point onwards it should work.

>>could not find input type = "file"

You found it. The tag you posted is the one you were looking for. The order of attributes doesn't matter.
No the site does not offer save the login info. is there an alternative solution so that  can log in automatically instead of manually?
Glad that you pointed out that I foun out the input type!
so I should just replace name=""file1"";  to name = ""file"" in the code that you posted?

 vPost = _
    "--------------f89awenrh8f8" & vbCrLf & _
    "Content-Disposition: form-data; name=""file1""; filename=""" & uFile & "" & vbCrLf & vbCrLf & _
    cPostData & vbCrLf & _
    "--------------f89awenrh8f8--"
>> so I should just replace name=""file1"";  to name = ""file"" in the code that you posted

Yes but it won't work yet because of the login. Can you get to the upload page without login?  You might be in luck. The login page you posted seems to use the GET instead of POST. Could you go to it and post the URL that you see BEFORE and AFTER hitting login button.
I am unable to get to the upload page without logging in. Also the before and after logging in url is the same..
Does it have something like

http://someDomain.com/SomePage.asp?statmess=Welcome&sid=a483028b5b1007eead5b6c55f625b52a

? If so post the URL. You can mask the domain name page name.
https://xxx.xxxxx.xx.gov/cgi-bin/wfr
that is the url before and after login in. I have replaced some of the letters with xxxx.  I can post the url and then maybe have soembody remove it from here - if you want to take a look or if you have a space in web where i can post ; that is fine too?
No I don't need to see the actual URL. Did you modify the view source you posted? Espacially the <form> tags. If so post the actual form tag. Again you can mask the identifiable information with xxxxxx.
no I did not modify the view source; I just did posted only parts of it..
I only copied the parts that had the text input type...I di not copy the whole view source
You had

<form name="status">

Did you modify this tag?
no I did not
Hmm, the server is taking GET request but is redirecting. This is even tougher to automate now. Is this your website or someone elses? Can you ask them to provide another page that doesn't use form authentication?
It is not my website. It is the website of a third party to which I have to upload reports
no they are not going to provide another page that does not use form authentication.
do you think the othe direction taht I have posted fromseraching this site would work...
any thoughts...
ok...In the meantime, I was tryinng to see if the code that you were helping out with would work for another website...
the view source before logging in (at the login page) is as follows:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<!-- Copyright (C) 2000 . -->
<!-- Copyright (C) 1999  -->
<!-- Copyright (C) 1998 c. -->
<!-- All Rights Reserved. -->
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>State of xx Login</TITLE></HEAD>
<SCRIPT language="JavaScript">
   
      function submitApplications()
      {
            document.forms[0].action ="/pkmslogin.form";
            document.forms[0].submit();
      }
      function submitForgotPassword()
      {
                if ( document.forms[0].username.value.length > 0 ){
            document.forms[0].action ="/som/dch-portal/ForgotPasswordServlet";
            document.forms[0].submit();
            }
            else {
                  alert("Please enter your user id and then click on I forgot my Password Link");
            }
      }

</SCRIPT>

<BODY BGCOLOR="#efefef" TEXT="#000000" onLoad="document.forms[0].username.focus()">

<FORM METHOD=post action="/pkmslogin.form">

<a href="http://michigan.gov"><IMG height=100 src="/pics/DCH.gif" width=650 border=0></a>
<br>
<!--- y do not have cookies configured on their browsers.  If this environment does
  not use cookies to maintain login sessions, simply remove or comment out the block below.
--->
<!--- BEGIN Cookie check block ---><!---
DO NOT TRANSLATE anything inside the SCRIPT tag except the quoted
string warningString.  i.e. var warningString = "Translate this string";
--->
<SCRIPT LANGUAGE=JavaScript>
var warningString = "<B>WARNING:</B> To maintain your login session, make sure that your browser is configured to accept Cookies.";
document.cookie = 'acceptsCookies=yes';
if(document.cookie == ''){
document.write(warningString);
}
else{
document.cookie = 'acceptsCookies=yes; expires=Fri, 13-Apr-1970 00:00:00 GMT';
}
</SCRIPT>
<NOSCRIPT>
<B>WARNING:</B> To maintain your login session, make sure that<BR>
your browser is configured to accept Cookies.
</NOSCRIPT>
<!--- END Cookie check block --->

<BR>
<!-- table BORDER="0" WIDTH="650" style="WIDTH: 698px; HEIGHT: 239px">
<tr>
<td valign="top" width="250" -->
<TABLE ALIGN="center" BORDER="0" width="60%">
   <TR >
    <TD ALIGN="middle">User ID</TD>
    <TD><INPUT NAME="username" SIZE="15"></TD>
   </TR>
   <TR>
    <TD ALIGN="middle">Password</TD>
    <TD><INPUT TYPE="password" NAME="password" SIZE="15"></TD>
   </TR>
   <TR><TD>&nbsp;</TD></TR>
   <TR>
     <TD colspan="2" align="middle">
       <INPUT TYPE="submit" VALUE="Login" >&nbsp;&nbsp;<INPUT type="button" value="Register *"
 onClick="location.href='/som/dch/enroll/reg_page1.jsp'" >
     </TD>
   </TR>
</TABLE>
<!-- /td>
<td width="400" valign="top">&nbsp;</td>
</table -->
<TABLE width="700">
 <TR><TD>&nbsp;</TD></TR>
 <TR>
   <TD colspan="3" STYLE="FONT-WEIGHT: bold" align="middle">
      <P>* If you do not have a username, please click "Register" to apply.</P>  
   </TD>
 </TR>
</TABLE>
<TABLE WIDTH="700">
 <TR>
  <TD align=middle><A href="javascript:submitForgotPassword()" ><FONT
      color=#0000ff>I forgot my
Password</FONT></A></TD>
 </TR>
</TABLE></FORM>
</BODY>
</HTML>



AFTER LOGGING IN IT EXPECTS ME TO CLICK ON A LINK(called DCH-File Transfer), view source is as follows:
<SCRIPT language="JavaScript">
<!--
document.cookie = "IV_JCT=/dch-filetran; path=/";
//-->
</SCRIPT>




<html>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<title>MDCH-BPCT </title>
<LINK REL='stylesheet' TYPE='text/css' HREF='css/mdchmain.css' />
</HEAD>
<body>
<form name="frm"  >
<table class="noBorder" width="750" cellspacing="1" cellpadding="0" border="0">
<tr>
<td><IMG height=100 alt="" src="images/mdchbanner.jpg" width=750 border=0></td>
</table>
<table width="750"  cellpadding="0" cellspacing="1" >
 <tr>
    <td>
      <table width="100%" cellpadding="3" cellspacing="1" >
        <tr class="indexTblHeading">
          <td>File</td>
        </tr>
        <tr>
          <td class="indexLinkLabel"><A href="upload.do">Upload File</A></td>
        </tr>
        <tr>
          <td class="indexLinkLabel"><A href="download.do?jboEvent=loadpage">Download File</A></td>
        </tr>
        <tr>
          <td class="indexLinkLabel">&nbsp;</td>        
        </tr>
        <tr>
          <td class="indexLinkLabel">&nbsp;</td>        
        </tr>
      </table>
    </td>
   
     <td>
      <table width="100%" cellpadding="3" cellspacing="1" >
        <tr class="indexTblHeading">
          <td>Browse</td>
        </tr>
        <tr>
          <td class="indexLinkLabel"><a href="loginfo.do?jboEvent=details">Upload Log</a></td>
        </tr>
        <tr>
          <td class="indexLinkLabel"><a href="downloadfileloginfo.do?jboEvent=details">Download Log</a></td>        
        </tr>
        <tr>
          <td class="indexLinkLabel">&nbsp;</td>        
        </tr>
        <tr>
          <td class="indexLinkLabel">&nbsp;</td>        
        </tr>
        </table>
      </td>
    <td>
      <table width="100%" cellpadding="3" cellspacing="1" >
        <tr class="indexTblHeading">
          <td>General</td>
        </tr>
        <tr>
          <td class="indexLinkLabel"><a href="newareaaccess.do?jboEvent=new">Request Additional Area Access</a></td>        
        </tr>
        <tr>
          <td class="indexLinkLabel"><A href="logout.do">Exit Application</a></td>
        </tr>
         <tr>
          <td class="indexLinkLabel">&nbsp;</td>        
        </tr>
        <tr>
          <td class="indexLinkLabel">&nbsp;</td>        
        </tr>
        </table>
      </td>
  </tr>
</table>
<br>
<table width="750" cellpadding="3" cellspacing="1">
<tr>
  <td colspan="3"><hr></td>
</tr>
<tr>
  <td width="250"><font face="Arial, Helvetica, sans-serif" size="-1">Version: 1.3<br>Last Updated: 10/31/2005</font></td>
  <td class="normalLabel" align="right">Logged in user: warrenb1640</td>
 </tr>
</table>
</form>
</body>
</html>



 WHICH THEN TAKES ME TO ANOTHER PAGE where I have to clcik on upload file link(view source as follows)
<SCRIPT language="JavaScript">
<!--
document.cookie = "IV_JCT=/dch-filetran; path=/";
//-->
</SCRIPT>




<html>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<title>MDCH-BPCT </title>
<LINK REL='stylesheet' TYPE='text/css' HREF='css/mdchmain.css' />
</HEAD>
<body>
<form name="frm"  >
<table class="noBorder" width="750" cellspacing="1" cellpadding="0" border="0">
<tr>
<td><IMG height=100 alt="" src="images/mdchbanner.jpg" width=750 border=0></td>
</table>
<table width="750"  cellpadding="0" cellspacing="1" >
 <tr>
    <td>
      <table width="100%" cellpadding="3" cellspacing="1" >
        <tr class="indexTblHeading">
          <td>File</td>
        </tr>
        <tr>
          <td class="indexLinkLabel"><A href="upload.do">Upload File</A></td>
        </tr>
        <tr>
          <td class="indexLinkLabel"><A href="download.do?jboEvent=loadpage">Download File</A></td>
        </tr>
        <tr>
          <td class="indexLinkLabel">&nbsp;</td>        
        </tr>
        <tr>
          <td class="indexLinkLabel">&nbsp;</td>        
        </tr>
      </table>
    </td>
   
     <td>
      <table width="100%" cellpadding="3" cellspacing="1" >
        <tr class="indexTblHeading">
          <td>Browse</td>
        </tr>
        <tr>
          <td class="indexLinkLabel"><a href="loginfo.do?jboEvent=details">Upload Log</a></td>
        </tr>
        <tr>
          <td class="indexLinkLabel"><a href="downloadfileloginfo.do?jboEvent=details">Download Log</a></td>        
        </tr>
        <tr>
          <td class="indexLinkLabel">&nbsp;</td>        
        </tr>
        <tr>
          <td class="indexLinkLabel">&nbsp;</td>        
        </tr>
        </table>
      </td>
    <td>
      <table width="100%" cellpadding="3" cellspacing="1" >
        <tr class="indexTblHeading">
          <td>General</td>
        </tr>
        <tr>
          <td class="indexLinkLabel"><a href="newareaaccess.do?jboEvent=new">Request Additional Area Access</a></td>        
        </tr>
        <tr>
          <td class="indexLinkLabel"><A href="logout.do">Exit Application</a></td>
        </tr>
         <tr>
          <td class="indexLinkLabel">&nbsp;</td>        
        </tr>
        <tr>
          <td class="indexLinkLabel">&nbsp;</td>        
        </tr>
        </table>
      </td>
  </tr>
</table>
<br>
<table width="750" cellpadding="3" cellspacing="1">
<tr>
  <td colspan="3"><hr></td>
</tr>
<tr>
  <td width="250"><font face="Arial, Helvetica, sans-serif" size="-1">Version: 1.3<br>Last Updated: 10/31/2005</font></td>
  <td class="normalLabel" align="right">Logged in user: sara</td>
 </tr>
</table>
</form>
</body>
</html>

after I click on upload file  link it  FINALLY takes me to the upload page:
view source as follows:
<SCRIPT language="JavaScript">
<!--
document.cookie = "IV_JCT=/dch-filetran; path=/";
//-->
</SCRIPT>





<html>
 <head>
 <title>File Upload </title>
 <LINK REL='stylesheet' TYPE='text/css' HREF='css/mdchmain.css' />
 <script language="javascript" type="text/javascript" src="js/BusyBox.js" />
 <script language="javascript" type="text/javascript">
    // Instantiate BusyBox object
    busyBox = new BusyBox("BusyBoxDiv", 4, "images/gears_ani_", ".gif", 125);
  </script>
  <script language="javascript" type="text/javascript">
  var show=0;
  function goIndex(){
    show=1;
    document.uploadForm.action="home.do";
    document.uploadForm.submit();  
  }
  function showBusyBox(){
   // alert(show);
    if(show==0){
      busyBox.Show();
    }
  }

 </script>
</head>
 <body bgcolor="#EFEFEF" onbeforeunload="showBusyBox();">
    <!--
            The most important part is to declare your form's enctype to be "multipart/form-data",
            and to have a form:file element that maps to your ActionForm's FormFile property
    -->
 <form name="uploadForm" method="post" action="/dch-filetran/filetransfer/upload-submit.do" enctype="multipart/form-data">
 
  <table  width="600" cellspacing="2" cellpadding="2" border="0">
    <tr>
    <td align="middle" class="screenLabel" colspan="3">File Upload</td>
    </tr>
  </table>
 
  <table  width="700" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="100%" class="normalLabel" valign="bottom" align="left">&nbsp;All fields marked with ' * ' are mandatory</td>    
    </tr>
  </table>
  <br>
 
  <div style="WIDTH:600">    
   
   
  </div>
       <div style="WIDTH:600">
  <fieldset>
  <table width="100%" cellpadding="2" cellspacing="2">
    <tr>
      <td class="requiredLabel">Area *</td>
      <td>
          <select name="areaId"><option value="1,MAPS">MAPS</option></select>&nbsp;&nbsp;(select from list if having multiple area access)
      </td>
    </tr>
    <tr>
      <td class="requiredLabel" width="30%">Select file to transfer *</td>
      <td><input type="file" name="theFile" value=""></td>
    </tr>
    <tr><td colspan="2">&nbsp;</td></tr>
  </table>
  </fieldset>
 </div>
  <br>
   <table width="600" cellpadding="2" cellspacing="2">
    <tr align="center">
      <td><input type="submit" value="Upload" class="Btn">
      &nbsp;&nbsp;<input type="button" name="Cancel" value="Cancel" onclick="goIndex();" class="Btn">      
    </tr>
  </table>  
   <div id="BusyBoxDiv" style="BORDER-RIGHT: navy 3px solid; PADDING-RIGHT: 10px; BORDER-TOP: navy 3px solid; PADDING-LEFT: 10px; VISIBILITY: hidden; PADDING-BOTTOM: 10px; BORDER-LEFT: navy 3px solid; PADDING-TOP: 10px; BORDER-BOTTOM: navy 3px solid; POSITION: absolute; BACKGROUND-COLOR: white"
                        align="center"><img id="animation" src="images/gears_ani_0.gif"><br>
                        <h3>Processing.....</h3>
      </div>


<input type="hidden" name="areaCount" value="1">
</form>
</body>
</html>


NOW FOR THE QUESTION , WILL UR CODE WORK FOR THIS TYPE OF A WEBSITE?
IF YES HOW DO I CODE FOR THE CLICKING ON LINKS TO TAKE ME TO THE ACTUALLY WEB PAGE PART ...BECAUSE THE AFTER THE FIRST LINK -- I DONT SEE THE ADDRESS IN THE ADDRESS BAR OF INTERNET EXPLORER..
ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America 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
so the form is posted and this website will work for the code direction taht u have given..

>>The basic step is to get the HTML, parse it for any input values that might be needed later, assemble the post data and post. Repeat the process for next page and so on.

Can you please explain with code for one page and that way I can proceed with the next pages..
>>Cookies (if used) will further complicate the situation in which case you might need a proxy so that you know what is being sent from the browser and what is being sent from the server.

Can you say if cookies are being used from the view source?
document.cookie = 'acceptsCookies=yes;
If the form mpost method is GET make the URL as

http://WhateverDomain.com/WhateverPage.asp?InputFieldName1=Value1&InputFieldName2=Value2&

and call the page. You will get the HTML.

If the form method is POST, the URL would be

http://WhateverDomain.com/WhateverPage.asp

and the data to be posted be

InputFieldName1=Value1&InputFieldName2=Value2&

I have given example for only 2 input fields. You need to either parse the HTML or do a view source ans extract all input fields and make the POST data.

This would work as long as the page is unauthenticated.

If the page needs cookie or not can't be determined by the code you have posted. You need to browse the site after you have disabled the cookie and see if the site still allows login. If not, it is using cookie to save some data. You need more tool to determine what data is beign saved and requested. Firefox can be of help in this.

how to determine if the form is using post or get?

HOW DO YOU CODE FOR CLICKING A LINK PART,.
FOR EXAMPLE WHEN U GO TO A PAGE IF YOU HAVE to click a link called submit pmp data?
<td><a id="btnSubmitData" class="linkbuttonmedium" href="javascript:__doPostBack('btnSubmitData','')">Submit PMP Data</a></td><td><span id="lblSubmit" class="labelstandard">Submit PMP data to GHS.</span></td>

will  "POST", vPost, vHeaders part of the code remain the same?

I understand that it is getting more involving, so I can even post another question with seprate points for your valuable help.
ok I ckind of figured out this form is using the form method of post from the foll. code:
<form name="PMP_Logon" method="post" action="PMP_Logon.aspx?ReturnUrl=%2fPMP%2fDefault.aspx" id="PMP_Logon">

so the code would be

Inet1.Execute "https://thewebsitename.gov/wfr/myfilename.asp", "POST", vPost, vHeaders

where should I include:
>>>and the data to be posted be

InputFieldName1=Value1&InputFieldName2=Value2&
also there are 3 names against the input type: which one should i use in the vpost(data to be posted)?
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" value="dDw4ODExMjE3MzM7dDw7bDxpPDE+Pjs+Ozs+Oz4+Pjs+Ozs+Oz4+Oz4+Oz4+Oz4+Oz4+Oz6HjA79HR6XtZBxZ4pcunH72Q9bag==" />
Please take a look at this link .
http://support.microsoft.com/kb/q167706/
Wil this be a easier solution?
>> where should I include:

vPost = "InputFieldName1=Value1&InputFieldName2=Value2"

>> <input type="hidden" name="__VIEWSTATE"

The destination page is .Net application. It makes it even more difficult as the .Net by default checks few more things about the post to make sure that the request has not been modified with - exactly what you are trying to do.

There are many easier way to do this if you can get the "external" site to cooprate. They can very simply give you a page or a web service (even better) to do this. The way you are trying to do is not only very hard and error prone, it is not maintainable also. Anytime the destination site changes the page a little - say just a new field or a field name change - your application would break.