Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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# 如何使用windows phone对文件进行base64编码并上载到PHP?_C#_Windows Phone 7_Windows Phone 8_Windows Phone - Fatal编程技术网

C# 如何使用windows phone对文件进行base64编码并上载到PHP?

C# 如何使用windows phone对文件进行base64编码并上载到PHP?,c#,windows-phone-7,windows-phone-8,windows-phone,C#,Windows Phone 7,Windows Phone 8,Windows Phone,我只想将.dat文件从windows phone上传到php脚本 这是我的代码,但不起作用。有人知道为什么吗 C: PHP: 您正在滥用HTTP协议 为服务器干杯。请务必阅读注释,而且您可能希望异步执行此操作。对于异步路径,我建议您尝试C语言新的async Wait功能,与开始/结束方法相比,它对此类任务非常有用。什么是不工作?发生了什么?为了回应上述评论,请描述您看到的行为和收到的任何异常。另外,如果最后只是保存文件,为什么要直接发布一个base 64字符串而不是文件内容? string fi

我只想将.dat文件从windows phone上传到php脚本

这是我的代码,但不起作用。有人知道为什么吗

C:

PHP:


您正在滥用HTTP协议


为服务器干杯。请务必阅读注释,而且您可能希望异步执行此操作。对于异步路径,我建议您尝试C语言新的async Wait功能,与开始/结束方法相比,它对此类任务非常有用。

什么是不工作?发生了什么?为了回应上述评论,请描述您看到的行为和收到的任何异常。另外,如果最后只是保存文件,为什么要直接发布一个base 64字符串而不是文件内容?
string fileBase64 = "UklGRt4lAABXQVZFZm10IBAAAAABAAEARKw...";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://...mysite.../upload.php");
request.Method = "POST";
request.ContentType = "application/octet-stream";

string postData = String.Format("file={0}", fileBase64);   

// Getting the request stream.
request.BeginGetRequestStream
    (result =>
    {
        // Sending the request.
        using (var requestStream = request.EndGetRequestStream(result))
        {
            using (StreamWriter writer = new StreamWriter(requestStream))
            {
                writer.Write(postData);
                writer.Flush();
            }
        }

        // Getting the response.
        request.BeginGetResponse(responseResult =>
        {
            var webResponse = request.EndGetResponse(responseResult);
            using (var responseStream = webResponse.GetResponseStream())
            {
                using (var streamReader = new StreamReader(responseStream))
                {
                    string srresult = streamReader.ReadToEnd();
                }
            }
        }, null);
    }, null);
    define("UPLOAD_DIR", "./uploads/");


    if(isset($_POST['file']))
    {
        $base64_string = $_POST['file'];
        $ifp = fopen( UPLOAD_DIR.'aaa.dat', "wb" ); 
        fwrite( $ifp, base64_decode($base64_string) ); 
        fclose( $ifp ); 

        echo "ok";
        echo $base64_string;
        echo base64_decode($base64_string);

    }else{
            echo "no submit";
        }