on 12-22-2014 7:34 AM
Hi All.
I want to upload file authenticated website using OLE method from PowerBuilder to WebBrowser. Below is my step which i have tried.
I am able to navigate the url, login and go to particular URL. Now I have struck at file upload level.
Variable type is coming as 'file' [Red Marked Line ], how to pass file path and name from PB. Below is my script
IE = CREATE OLEObject
IE.ConnectToNewObject("InternetExplorer.Application")
IE.left=200
IE.top=200
IE.height=400
IE.width=400
IE.menubar=1
IE.toolbar=1
IE.statusBar=1
IE.navigate("http://www.xyz.in/index.php")
li_form_ctr = IE.Document.Forms.Length
if li_form_ctr = 1 then
li_form_ctr = li_form_ctr - 1
IE.Document.Forms[li_form_ctr].Elements.username.Value = 'Test'
IE.Document.Forms[li_form_ctr].Elements.password.Value = 'test@123'
ls_OldURL = IE.LocationURL
IE.Document.Forms[li_form_ctr].Elements.submit.Click()
else
return
end if
DO WHILE IE.Busy
Yield ()
LOOP
if ls_OldURL = IE.LocationURL then
messagebox("Error","Either User Name/Password Wrong")
else
IE.navigate("http://www.xyz.in/upload_ecr_latest.php")
DO WHILE IE.Busy
Yield ()
LOOP
sleep(2)
li_form_ctr = 0
li_form_ctr = IE.Document.Forms.Length
if li_form_ctr = 1 then
li_form_ctr = li_form_ctr - 1
IE.Document.Forms[li_form_ctr].Elements.month.Value = '08'
IE.Document.Forms[li_form_ctr].Elements.year.Value = '2014'
IE.Document.Forms[li_form_ctr].Elements.ecr = "D:\temp\xyz.txt" -- This one is not working
ls_OldURL = IE.LocationURL
IE.Document.Forms[li_form_ctr].Elements.upload.Click()
else
return
end if
end if
Narayana
AFAIK, you can't set the value for input type = "file" by script because of security reasons.
Arnd
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have a sample that uses WinHTTP API functions to support HTTP Put. It is similar to the built in PostURL function except it supports secure URLs and is easier to use.
Dear Roland,
Thanks for the quick reply.
I have tried WinHTTP and i am getting "HTTP Post Error #12002". Please find Below modified script. I have created function for below script and calling in place of file upload.
n_winhttp ln_http
String ls_filename,ls_path_name
String ls_filter, ls_mimetype, ls_data
Integer li_rc, li_fnum
ULong lul_length
ls_filename = 'xyz.txt'
ls_path_name = 'D:\temp\xyz.txt'
li_fnum = FileOpen(ls_path_name, TextMode!, Read!)
lul_length = FileReadEx(li_fnum, ls_data)
FileClose(li_fnum)
SetPointer(HourGlass!)
ln_http.SetWriteProgress(Handle(this), 1024)
ls_URL = "http://www.xyz.in/upload_ecr_latest.php?filename="+ ls_filename
//ls_URL += "/winhttp/roland_post.asp?filename=" + ls_filename
ls_mimetype = ln_http.GetMIMEType(ls_filename, ls_data)
ln_http.Open("POST", ls_URL)
ln_http.SetRequestHeader("Content-Length", String(lul_length))
ln_http.SetRequestHeader("Content-Type", ls_mimetype)
lul_length = ln_http.Send(ls_data)
If lul_length > 0 Then
mle_response.text = ln_http.ResponseText
st_msg.text = "Post Complete in " + &
String(ln_http.Elapsed, "#,##0.####") + " seconds."
Else
MessageBox("HTTP Post Error #" + &
String(ln_http.LastErrorNum), &
ln_http.LastErrorText, StopSign!)
End If
Narayana
Error 12002 is: The request has timed out.
It could be an issue with your script or maybe write permissions on the website. I included a file post.asp that can be used to test with. It is Classic ASP (vbscript). You could try posting to it instead. First try it with the stream functions commented out so all it does is return the number of bytes received.
I guess I forgot to include it. Save the below text to a file called post.asp and upload to your website.
<%
Response.ContentType="text"
set stream=Server.CreateObject("ADODB.Stream")
filename = Server.MapPath(Request("filename"))
count = Request.TotalBytes
buffer = Request.BinaryRead(count)
stream.Open
stream.Type=1 ' 1=Binary, 2=Text (Default)
stream.Write buffer
stream.SaveToFile filename
stream.Close
Response.Write "Bytes Received: " & count & ", Filename: " & filename
%>
Dear Roland,
Thank you for the reply
Merry Christmas!!!
I have uploaded post.asp to my local website and it is working fine using post.asp. But i am trying to upload file to Government statutory website which fails. Even-though i am go-ogling and trying alternative method but no success. If you find any method please update me, thanks in advance
Narayana
User | Count |
---|---|
87 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.