I want to post-send the file from the UWP application to the PHP application on the server side, but the file fails to be sent.
The failure is that the $_FILES decision on the PHP side is always false.
I have sent two parameters.
- param1 is a string value
- param2 is the upload file
if ($_FILES['param2'])
private async Task PostSample()
{
const string POST_URL = "http://xxx.xxx.xxx.xxx/api/sample.php";
var multi=new HttpMultipartFormDataContent();
varparam1 = new HttpStringContent("foo");
multi.Add (param1, "param1");
byte [ ] values = new byte [ ] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 };
varparam2 = new HttpStreamContent(new MemoryStream(values).AsInputStream());
param2.Headers.ContentDisposition=newWindows.Web.Http.Headers.HttpContentDispositionHeaderValue("form-data")
{
Name = "param2",
FileName="piyo.dat"
};
multi.Add (param2);
varclient = new HttpClient();
var res = wait client.PostAsync (new Uri(POST_URL), multi);
vardiag = new MessageDialog(res.ToString());
wait diag.ShowAsync();
}
The Google Chrome app Advanced REST Client
succeeded (if($_FILES['param2']) is true.
private async Task PostSample()
{
const string POST_URL = "http://xxx.xxx.xxx.xxx/api/sample.php";
var multi=new MultipartFormDataContent();
var param1 = new StringContent("foo");
multi.Add (param1, "param1");
byte [ ] values = new byte [ ] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 };
varparam2 = new StreamContent (new MemoryStream (values));
param2.Headers.ContentDisposition=newSystem.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
{
Name = "param2",
FileName="piyo.dat"
};
multi.Add (param2);
varclient = new HttpClient();
var res = wait client.PostAsync(POST_URL, multi);
MessageBox.Show(res.ToString());
}
Therefore,
I suspect that the code on the UWP side is incorrect, missing, or some specification on the UWP side, but I don't know why.
I would appreciate it if you could give me some advice on the direction of the investigation.
It may be inappropriate, but I also posted it on the English version of Stackoverflow yesterday.However, it seems that the view doesn't work in the first place, so I also posted it here.
If it is not appropriate, I will delete it, so I would appreciate it if you could let me know.
https://stackoverflow.com/questions/40988582/post-transmission-of-file-fails-with-uwp
php c# .net http win-universal-app
If WinForm works with almost the same code, it is possible that the app does not have permission to send data to the outside world.
© 2024 OneMinuteCode. All rights reserved.