从VB.NET应用程序发送文件到PHP脚本
I need to send some data from a SQL DB Server on an internal network to an external web server.
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.
What is a good method to send data to a PHP script from a .NET app?
我需要将一些数据从内部网络上的SQL DB服务器发送到外部Web服务器。 p >
我希望通过编写一个每天调用一次的VB.NET应用程序来实现这一目标,该应用程序将大约1 MB的数据发送到Web服务器上的PHP脚本,并存放在数据库中 。 p>
从.NET应用程序向PHP脚本发送数据有什么好方法? p> div>
You can use the HTTPWebRequest class to post a file to your php script just as a browser would. If the file you are sending is text based like XML or CSV, a simple post could be done. 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. 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.
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.
In terms of specific functions, etc. PHP has a wide range of FTP related functions (key docs here). 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.
You might want to use JSON or XML.
Web services would be the way to go, perhaps SOAP via XML to push the data directly to 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. If you want PHP to process the data immediately when it's received, you'll probably need the first option.
Another idea could be to execute a HTTP PUT request to PHP based website and transfer your data.
Find here how to accept content sent through HTTP Put in 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