0

I am soon looking at coding a C# Application out of my spare time for a friend of mine, this application will essentially be uploading files from the clients computer to a PHP webscript, using the WebClient Class and its UploadFile Method. I am currently planning out exactly how the script will communicate with the server, and then how it will receive a response containing some information regarding the users upload to the server.

Step 1: User will select file(s) to be uploaded, they will then upload them

Step 2: The program will communicate with a PHP script on our server, which will process through the uploads and upload them to the correct folder

Step 3: The PHP server will then simply respond with a string, array or some sort of response which will be relayed back to the program, this will contain important information, such as;

  • Username
  • A link
  • Date/Time on server uploaded
  • An error status

I was thinking the best way to do this was via an array of some sort, however I am lost at this point as I have never really delved into this. I have been told that simply outputting a PHP Array will not do the trick, and I will need to use other means such as JSON or XML. Does anyone have any recommendations for how I should handle the returned data, which I will need to use on the software to display a link and other information such as the date & time(which will actually be in timestamp format).

Cheers,

4

2 回答 2

3

由于您正在处理跨语言通信,因此 JSON 确实是最好的格式。XML 也可以很好地工作,但我发现 XML 有点过于冗长,因为只是为了传输数据。

简单地....

 json_encode($array) 

...您的数组,然后发送数据。您可以轻松地在 C# 端解析这些数据。对于您希望发送数据以用于多种语言的大多数场景,JSON 是最佳格式。

于 2012-09-03T02:47:37.820 回答
1

转储 PHP 数组将不起作用,因为 PHP 有它自己的序列化程序,而 c# 不能(也许它可以,但它不实用)读取它。

使用 JSON 或 XML 的建议是正确的,这两种格式非常适合传输数据。我会说坚持使用 JSON,但这只是个人喜好。它们都适用于该目的,并且 XML 和 JSON 在 c# 和 PHP 中都有本机实现。

编辑:

于 2012-09-03T02:48:17.617 回答