Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将图像作为流从WP8发送到WCF,并使用REST,不带“";标题“;_C#_Wcf_Rest_Windows Phone 8 - Fatal编程技术网

C# 将图像作为流从WP8发送到WCF,并使用REST,不带“";标题“;

C# 将图像作为流从WP8发送到WCF,并使用REST,不带“";标题“;,c#,wcf,rest,windows-phone-8,C#,Wcf,Rest,Windows Phone 8,我有我的WP8和WFC之间的连接工作,我可以发送一个图片作为流(字节数组) 服务方 [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "FileUpload/{fileName}")] string SendImageToDB(string fileName, Stream fileStream); SendImageToDB public void SendSteamToDB(byte[] stream

我有我的WP8和WFC之间的连接工作,我可以发送一个图片作为流(字节数组)

服务方

[OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "FileUpload/{fileName}")]
    string SendImageToDB(string fileName, Stream fileStream);
SendImageToDB

public void SendSteamToDB(byte[] stream)
    {
        MySqlConnection connection = new MySqlConnection(MyconSQL);
        MySqlCommand cmd;
        connection.Open();

        try
        {
        cmd = connection.CreateCommand();
        cmd.CommandText = "UPDATE PIC SET pic_link=@image WHERE id = '1';";
        cmd.Parameters.Add("@image", MySqlDbType.Blob).Value = stream;
        cmd.ExecuteNonQuery();
        }
        catch (MySqlException ex)
        {
            Console.Write("Error: {0}", ex.ToString());
        }
        finally
        {
            if (connection != null)
            {
                connection.Close();
            }
        }
    }
windows phone端

private void Upload_Click(object sender, EventArgs e)
    {

        string imageID = "test";
        var client = new RestClient("http://192.168.1.130:53715//Service1.svc");
        var request = new RestRequest("FileUpload/{imageName}", Method.POST);
        request.AddUrlSegment("imageName", imageID);
        request.AddFile("image/jpeg", myImage, imageID);

        client.ExecuteAsync(request, response =>
        {
        });
        try
        {
            client.ExecuteAsync(request, response =>
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    MessageBox.Show("Upload succes!");
                }
                else
                {
                    MessageBox.Show(response.StatusCode.ToString());
                    MessageBox.Show("Upload error!");
                }
            });
        }
        catch (Exception error)
        {
            MessageBox.Show("error" + error);
        }   
     }
所有这些都工作正常,只有一个问题我放入数据库的字节数组有某种“头”

是否将字节数组放入.txt中

避免这种情况的最佳方法是什么?

这里的答案显示了如何解码该格式。