简体   繁体   English

Android Javascript交互-尝试将文件上传到CGI

[英]Android javascript interaction - trying to upload file to CGI

Alright, so let me preface this by saying that I'm really unsure as to what I'm doing here and if it is at all possible. 好吧,让我在开头说一下,我真的不确定自己在这里做什么以及是否有可能。

I'm trying to build an android app that will interact with a pre-existing website. 我正在尝试构建一个与现有网站互动的android应用。 The site has a field to browse for a file, and a button upload it. 该站点有一个用于浏览文件的字段,并有一个按钮将其上传。 Hitting upload opens a /upload.cgi which seems to do the uploading itself before redirecting to a results page. 点击上载会打开一个/upload.cgi,它似乎在重定向到结果页面之前先进行上载。

Is it possible to use the underlying javascript to upload a file without having to use the pre-existing GUI that the website presents? 是否可以使用底层javascript上传文件而无需使用网站提供的预先存在的GUI? I would like to just use my own interface, but have it interact with what the website has. 我只想使用我自己的界面,但要使其与网站上的内容交互。

Thanks, and apologies for the vagueness. 谢谢,并为您的含糊表示歉意。

You maybe able to get it working using the Java/JavaScript bridge to submit the form for you (using a WebView). 您也许可以使用Java / JavaScript桥(通过WebView)为您提交表单,使其工作。 But my guess is it would be more trouble than it's worth. 但是我的猜测是,这将比其价值更大。 And you should be able to do it directly in Java using a post. 而且您应该能够使用帖子直接在Java中进行操作。

Files in HTML forms are normally uploaded using a multipart form encoded post body. HTML表单中的文件通常使用多部分表单编码的帖子正文上载。 Something like this: 像这样:

<form enctype="multipart/form-data" action="upload.cgi" method="POST">
   <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
   Choose a file to upload: <input name="uploadedfile" type="file" /><br />
   <input type="submit" value="Upload File" />
</form>

All you need to do is create the same post request that the form would generate. 您需要做的就是创建表单将生成的相同的发帖请求。 Here are a few links to get you started with creating multipart post request on Android. 以下是一些链接,可帮助您开始在Android上创建多部分帖子请求。

How use multipart/form-data upload picture/image on Android 如何在Android上使用多部分/表单数据上传图片/图像

http://w3mentor.com/learn/java/android-development/android-http-services/example-of-multipart-post-using-android/ http://w3mentor.com/learn/java/android-development/android-http-services/example-of-multipart-post-using-android/

http://www.17od.com/2010/02/18/multipart-form-upload-on-android/ http://www.17od.com/2010/02/18/multipart-form-upload-on-android/

http://evgenyg.wordpress.com/2010/05/01/uploading-files-multipart-post-apache/ http://evgenyg.wordpress.com/2010/05/01/uploading-files-multipart-post-apache/

Here's a debugging tip if you get stuck: You can installed fiddler as a reverse proxy on the CGI server, then you can watch both requests (HTML and Java) as they happen to compare them for differences. 如果遇到问题,这是一个调试提示:您可以将fiddler作为反向代理安装在CGI服务器上,然后可以观察两个请求(HTML和Java)碰巧比较它们之间的差异。 http://www.fiddler2.com/fiddler/help/reverseproxy.asp just remove it for production. http://www.fiddler2.com/fiddler/help/reverseproxy.asp只需将其删除即可生产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM