将图像上传到服务器并读取响应

时间:2013-08-10 08:23:23

标签: c# xaml windows-phone

我已将图像文件发布到具有php文件的服务器。

我使用了以下代码:

void photoChooserTask_Completed(object sender, PhotoResult e)
{
    if (e.TaskResult == TaskResult.OK)
    {

        byte[] sbytedata = ReadToEnd(e.ChosenPhoto);
        string s = sbytedata.ToString();
        WebClient wc = new WebClient();
        Uri u = new Uri("http://example.com/file.php");
        wc.OpenWriteCompleted+=new OpenWriteCompletedEventHandler(wc_OpenWriteCompleted);
        wc.OpenWriteAsync(u, "POST", sbytedata);

    }
}

public static void wc_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e)
{
    if (e.Error == null)
    {
        object[] objArr = e.UserState as object[];
        byte[] fileContent = e.UserState as byte[];

        Stream outputStream = e.Result;
        outputStream.Write(fileContent, 0, fileContent.Length);
        outputStream.Flush();
        outputStream.Close();
        string s = e.Result.ToString(); 

    }
}

但是如何从服务器读取返回图像文件的响应以及如何显示该图像?

0 个答案:

没有答案