简体   繁体   English

从VB.NET应用程序发送文件到PHP脚本

[英]Send a file to a PHP script from a VB.NET app

I need to send some data from a SQL DB Server on an internal network to an external web server. 我需要将一些数据从内部网络上的SQL DB服务器发送到外部Web服务器。

I was hoping to accomplish this by writing a VB.NET app that is invoked once per day that sends about 1 MB of data to a PHP script on the web server, where it is deposited in a database. 我希望通过编写一个VB.NET应用程序来实现这一目标,该应用程序每天调用一次,将大约1 MB的数据发送到Web服务器上的PHP脚本,并存放在数据库中。

What is a good method to send data to a PHP script from a .NET app? 从.NET应用程序向PHP脚本发送数据的好方法是什么?

You can use the HTTPWebRequest class to post a file to your php script just as a browser would. 您可以使用HTTPWebRequest类将文件发布到您的php脚本,就像浏览器一样。 If the file you are sending is text based like XML or CSV, a simple post could be done. 如果您要发送的文件是基于文本的XML或CSV,则可以执行简单的发布。 However, if you need to send binary data, you could either encode it base64 and then decode it on the other end in PHP, or post it as a file, using multipart forms . 但是,如果您需要发送二进制数据,您可以将其编码为base64,然后在PHP的另一端对其进行解码,或者使用多部分表单将其作为文件发布。 Unless you have a specific reason to be using multipart forms, it probably isn't worth all the extra trouble, and you should probably just encode your data with base64. 除非您有特定的理由使用多部分表单,否则可能不值得所有额外的麻烦,您应该只使用base64对数据进行编码。

Web services would be the way to go, perhaps SOAP via XML to push the data directly to PHP. Web服务将是可行的方式,也许是通过XML的SOAP将数据直接推送到PHP。

If you go middaparka's route, you're not pushing it directly to PHP, but rather just making it available to PHP using an include statement. 如果你去middaparka的路线,你不是直接推送到PHP,而只是使用include语句将它提供给PHP。 If you want PHP to process the data immediately when it's received, you'll probably need the first option. 如果您希望PHP在收到数据时立即处理数据,您可能需要第一个选项。

If you're after a reliable means, I'd be tempted to use FTP as a means of data transfer rather than HTTP - it'll make things a lot easier to manage in terms of error handling, etc. especially if you follow some good practices such as uploading the files into a temporary folder and then moving (renaming in FTP terms) them to a pickup folder once the upload is complete. 如果你是一个可靠的手段,我很想使用FTP作为数据传输的手段而不是HTTP - 它会使事情在错误处理等方面变得更容易管理,特别是如果你遵循一些好的做法,例如将文件上传到临时文件夹,然后在上传完成后将它们移动(以FTP术语重命名)到拾取文件夹。

In terms of specific functions, etc. PHP has a wide range of FTP related functions ( key docs here ). 在特定功能等方面,PHP具有广泛的FTP相关功能( 这里是关键文档 )。 I'm unfortunately not aware of the relevant .NET framework bits and bobs, but I'm sure someone here will point you in the right direction if MSDN doesn't deliver the goods. 遗憾的是,我不知道相关的.NET框架和bobs,但我相信如果MSDN没有交付货物,这里有人会指出正确的方向。

您可能想要使用JSON或XML。

Another idea could be to execute a HTTP PUT request to PHP based website and transfer your data. 另一个想法可能是对基于PHP的网站执行HTTP PUT请求并传输您的数据。

Find here how to accept content sent through HTTP Put in PHP http://php.net/manual/en/features.file-upload.put-method.php 在这里找到如何接受通过HTTP发送的内容放入PHP http://php.net/manual/en/features.file-upload.put-method.php

See here how you can execute HTTP PUT request from .net Application http://www.java2s.com/Code/CSharp/Network/HTTPputwithusernameandpassword.htm 请参阅此处如何从.net应用程序执行HTTP PUT请求http://www.java2s.com/Code/CSharp/Network/HTTPputwithusernameandpassword.htm

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

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