Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.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.1]远程服务器返回错误:“0”;“错误请求”;在WP8.1RT中将sqlite数据库文件上载到服务器时?_C#_.net_Windows Runtime_Windows Phone 8.1 - Fatal编程技术网

C# [WP8.1]远程服务器返回错误:“0”;“错误请求”;在WP8.1RT中将sqlite数据库文件上载到服务器时?

C# [WP8.1]远程服务器返回错误:“0”;“错误请求”;在WP8.1RT中将sqlite数据库文件上载到服务器时?,c#,.net,windows-runtime,windows-phone-8.1,C#,.net,Windows Runtime,Windows Phone 8.1,大家好, 在这里,我正在将一个WindowsPhone8.1应用程序的sqlite数据库文件上载到服务器上。但是,我在服务器上收到了一个错误的“错误请求” 请求EndGetResponse(结果) 请解释一下我做错了什么 谢谢呼叫时服务器上发生了什么?是服务器返回了错误。我收到一个错误,客户端发送的请求在语法上不正确。据我所知,整个代码都是正确的。 private async Task start() { var app = Application.Current as

大家好,

在这里,我正在将一个WindowsPhone8.1应用程序的sqlite数据库文件上载到服务器上。但是,我在服务器上收到了一个错误的“错误请求” 请求EndGetResponse(结果)

请解释一下我做错了什么


谢谢

呼叫时服务器上发生了什么?是服务器返回了错误。我收到一个错误,客户端发送的请求在语法上不正确。据我所知,整个代码都是正确的。
private async Task start()
    {
        var app = Application.Current as App;

            directory = "database";

            filePath = directory + "\\" + "db.sqlite";
            fileName = "db.sqlite";
            fileType = "application/octet-stream";

            try
            {                   
                        DoWork();
            }
            catch
            {

            }

    }
   async void DoWork()
    {
        if (NetworkInterface.GetIsNetworkAvailable())
        {
            try
            {

                var file =await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(filePath);

                    using (IRandomAccessStream fileStream = await file.OpenReadAsync())
                    {
                        byte[] buffer;

                            buffer = new byte[1024 * 1024 * 1];

                            fileStream.AsStream().Seek(0, SeekOrigin.Begin);
                            bytesRead = fileStream.AsStream().Read(buffer, 0, buffer.Length);

                    }


                request = (HttpWebRequest)WebRequest.Create(Utils.DataBaseUploadUri());
                request.AllowReadStreamBuffering = false;
                request.Method = "POST";
                request.ContentType = "multipart/form-data; boundary=" + boundary;


                request.BeginGetRequestStream(async (eRequest) =>
                {
                var localfile= await ApplicationData.Current.LocalFolder.GetFileAsync(filePath) ;  
                        using (IRandomAccessStream fileStream =await localfile.OpenReadAsync())
                        {
                            byte[] boundaryData = Encoding.UTF8.GetBytes(twoHyphens + boundary);
                            byte[] boundaryData1 = Encoding.UTF8.GetBytes(twoHyphens + boundary + twoHyphens);
                            string headertemp = "Content-Dis-data; name=\"attachment\";filename=\"" + "db" + ".sqlite" + "\"";
                            string Videotype = "Content-Type: " + fileType;
                            byte[] videtype = Encoding.UTF8.GetBytes(Videotype);
                            byte[] headerData = Encoding.UTF8.GetBytes(headertemp);
                            byte[] lineend = Encoding.UTF8.GetBytes(lineEnd);

                            using (Stream stream = request.EndGetRequestStream(eRequest))
                            {
                                stream.Write(boundaryData, 0, boundaryData.Length);
                                stream.Write(lineend, 0, lineend.Length);
                                stream.Write(headerData, 0, headerData.Length);
                                stream.Write(lineend, 0, lineend.Length);
                                stream.Write(videtype, 0, videtype.Length);
                                stream.Write(lineend, 0, lineend.Length);
                                stream.Write(lineend, 0, lineend.Length);
                                byte[] buffer = new byte[1024 * 1024 * 1];


                                    fileStream.AsStream().Seek(0, SeekOrigin.Begin);
                                    bytesRead = fileStream.AsStream().Read(buffer, 0, (int)fileStream.AsStream().Length);




                                stream.Write(buffer, 0, bytesRead);
                                stream.Write(lineend, 0, lineend.Length);
                                stream.Write(boundaryData1, 0, boundaryData.Length);
                                stream.Flush();
                                stream.Dispose();
                                request.BeginGetResponse(new AsyncCallback(RequestCompleted), request);
                                allDone.WaitOne();
                            }
                        }

                }, null);
            }
            catch (Exception)
            {


            }
        }
        else
        {
            //MessageBox.Show("Network not available.", "No network!", MessageBoxButton.OK);
        }
    }
   async void RequestCompleted(IAsyncResult result)
    {
        bool webexceptioRaised = false, exceptionRaised = false, webExceptionCancelled = false;

            try
            {
                HttpWebRequest req = (HttpWebRequest)result.AsyncState;
                HttpWebResponse responce = (HttpWebResponse)req.EndGetResponse(result);
                StreamReader str = new StreamReader(responce.GetResponseStream());
                parseString = str.ReadToEnd();
                failedCount = 0;

                if (parseString.Contains("XXX"))
                {

                }
                else
                {

                }
                allDone.Set();
            }
            catch (WebException ex)
            {
                if (ex.Status.Equals(WebExceptionStatus.RequestCanceled))
                {

                    webExceptionCancelled = true;

                }
                else
                {
                    if (ex.Response != null)
                    {

                    }


                }

                allDone.Set();
            }
            catch (Exception ex)
            {
               allDone.Set();
            }
            if (webExceptionCancelled)
            {

            }

    }