以编程方式将文件上传到网站吗? [英] Upload a file to a website programmatically?

查看:129
本文介绍了以编程方式将文件上传到网站吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用拉撒路(Lazarus),我有一个带有Webbrowser组件的应用程序,它可以登录到网站,并按如下所示加载页面(请参见下面的html代码),并填写不同的输入.最后输入的是要上传的文件.我希望我的应用程序单击"浏览,选择我想要的文件,然后打开.之后,我可以发布表格,也可以只是上传文件并继续.

I am using Lazarus I have an app with webbrowser component on it that logs into a website loads a page as below (see html code below), and fills in different inputs. The last input is a file to upload. I would like my app to "click" Browse, select a file i want to, and Open. After that I could do a post the form OR just upload the file and carry on.

我在网站上有以下html代码:

I have the following html code on the site:

<td align="left" class="RequiredInput">File:</td>
<td class="datafield">
 <form name="frmMain" id="frmMain" action="upload.asp?step=2&output=1" method="post" enctype="multipart/form-data">
    <input type="file" name="filename" id="filename">
</form>

我尝试从我的应用程序执行JS:document.getElementById('filename').value ='C:\ x.csv'

I tried executing JS from my app : document.getElementById('filename').value = 'C:\x.csv'

我尝试使用以下来自 synapse 的代码 HttpPostFile :

I tried using the following code HttpPostFile from synapse:

uFileName := 'C:\x.csv';
uStream := TFileStream.Create(uFileName, fmOpenRead);
uList:=TStringList.Create;  
if HttpPostFile('upload.asp?step=2&output=1', 'filename', uFileName, uStream, uList) then
 ShowMessage('OK');   

它什么也没做(我用 Fiddler 跟踪了应用的活动)

It did nothing at all (I followed the activity of the app with Fiddler)

任何帮助将不胜感激.

Any help would be appreciated.

预先感谢

Zsolt

推荐答案

这是一个已知问题,并且有解决方案,但是您必须将其从С#转换为Delphi.

This is a known problem, and there is a solution, but you're going to have to convert it from С# to Delphi.

另一种可能的解决方案是使用

Another possible solution is to upload the file using URL Moniker APIs. The upload will then happen on the same session the WebBrowser control is already using. There is an MSKB article:

如何在可插拔协议处理程序中处理POST请求

与文章链接的POSTMON.EXE示例已从Microsoft网站上消失,但仍可以找到此处.

The POSTMON.EXE sample linked to the article has disappeared from Microsoft website, but still can be found here.

这篇关于以编程方式将文件上传到网站吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆