首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过Webclient的Windowsphone到PHP通信

通过Webclient的Windowsphone到PHP通信
EN

Stack Overflow用户
提问于 2013-11-05 11:55:51
回答 1查看 213关注 0票数 1

我想上传一个我选择的图片与PhotoChooserTask。选择本身工作良好,我可以打开图像。我还将其解码为Base64 (Works)。

由于我找不到关于如何在windowsphone上使用httpwebrequest的任何工作示例,所以我尝试了以下方法。

代码语言:javascript
复制
    private void photoChooserTask_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {

            //Code to display the photo on the page in an image control named myImage.
            System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
            bmp.SetSource(e.ChosenPhoto);
            MyImage.Source = bmp;

            String str = BitmapToByte(MyImage);

            String url = "http://klopper.puppis.uberspace.de/php/app/image.php?image="+ str;

            LoadSiteContent(url);

        }


    }

其余的代码运行良好。

我明白了: System.IO.FileNotFoundException

如果我把str改为"test“,它就能工作了。

问题是,字符串太长了吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-05 13:06:49

代码语言:javascript
复制
 private void task_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult != TaskResult.OK)
            return;

        const int BLOCK_SIZE = 4096;

        Uri uri = new Uri("http://localhost:4223/File/Upload", UriKind.Absolute);

        WebClient wc = new WebClient();
        wc.AllowReadStreamBuffering = true;
        wc.AllowWriteStreamBuffering = true;

        // what to do when write stream is open
        wc.OpenWriteCompleted += (s, args) =>
        {
            using (BinaryReader br = new BinaryReader(e.ChosenPhoto))
            {
                using (BinaryWriter bw = new BinaryWriter(args.Result))
                {
                    long bCount = 0;
                    long fileSize = e.ChosenPhoto.Length;
                    byte[] bytes = new byte[BLOCK_SIZE];
                    do
                    {
                        bytes = br.ReadBytes(BLOCK_SIZE);
                        bCount += bytes.Length;
                        bw.Write(bytes);
                    } while (bCount < fileSize);
                }
            }
        };

        // what to do when writing is complete
        wc.WriteStreamClosed += (s, args) =>
        {
            MessageBox.Show("Send Complete");
        };

        // Write to the WebClient
        wc.OpenWriteAsync(uri, "POST");
    }

参考to post image file in windows phone 7 application

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19788410

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档