下面的代碼試圖利用的multipart/form-data的上傳圖像到服務器:WP8上傳圖像,得到錯誤
public async void PostRequest(Stream photoStream, string lomail, string fileName)
{
try
{
using (HttpClient client = new HttpClient())
{
client.Timeout = TimeSpan.FromMinutes(10);
photoStream.Position = 0;
using (MultipartFormDataContent content = new MultipartFormDataContent())
{
content.Add(new StringContent(lomail), "lomail");
content.Add(new StreamContent(photoStream), "photo", fileName);
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("post");
});
HttpResponseMessage response = await client.PostAsync(LoUrl, content);
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show(response.ToString());
});
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("finish");
});
}
}
}
catch (Exception e)
{
MessageBox.Show("post request: " + e.Message);
}
}
但有HTTP錯誤:(狀態碼404 ,Http.StramContent,Header:Content-length = 0)
這是怎麼回事?
請問您能解釋一下a)您想做什麼,b)您嘗試過什麼,c)您遇到什麼問題?你實際上沒有問過什麼:) – Ben
對不起!這是我在stackowerflow上的第一個問題。我試圖上傳圖像到服務器,但我有狀態碼404錯誤。 –
沒問題,歡迎來到StackOverflow。您確信您發佈的網址正確嗎?服務器是否正常工作,即是否可以手動上傳到相同的URL? – Ben