【发布时间】:2014-10-06 19:57:37
【问题描述】:
我正在使用 Windows Phone 8.0,尝试从手机向网站提交发布请求时遇到问题。名为“file”的输入,它只接受图像文件。
<form action="upmeme" method="post" enctype="multipart/form-data">
<input type="file" class="file" name="file" id="file"><br>
<input type="submit" class="submit" name="submit" value="Submit">
</form>
或者您可以访问这里:this website
我使用 PhotoPicker 从库中选择照片并将其保存到“照片”Stream photo = e.ChosenPhoto; 中,效果很好。
现在我需要上传照片并提交上面的表格。这是我调用发送帖子请求的代码,但它不起作用,响应与登顶前相同
photo.Position = 0;
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(url);
HttpRequestMessage request = new HttpRequestMessage();
MultipartFormDataContent form = new MultipartFormDataContent();
form.Add(new StreamContent(photo),"file");
HttpResponseMessage response = await client.PostAsync(url, form);
string responseBodyAsText = await response.Content.ReadAsStringAsync();
我尝试在 Internet 上四处查看,发现与我的结果相同。我的代码有问题吗?
【问题讨论】:
-
我已经实现了一些简单的HTTP类上传文件,看看mytoolkit.codeplex.com/wikipage?title=Http,章节“HTTP POST”
标签: c# html wpf windows-runtime