简体   繁体   English

c#webClient上传字符串中断

[英]c# webClient Upload String cuts off

I need some help with the C# WebClient UploadString Method. 我需要有关C#WebClient UploadString方法的帮助。 I'm trying to upload a long string (that I read from a database) to a server (PHP) and I'm currently trying to do that with the UploadString Method because it seemed to be the easiest. 我正在尝试将一个长字符串(从数据库中读取)上传到服务器(PHP),并且我目前正在尝试使用UploadString方法执行此操作,因为这似乎是最简单的方法。 The problem that I have is that the string that I upload gets cut off after about 4000 characters and I can't figure out why. 我的问题是我上传的字符串在大约4000个字符后被切断,我不知道为什么。 For Example: data.length: 19000 (before Upload) Post.length: 4000 (in PHP) 例如:data.length:19000(上传之前)Post.length:4000(在PHP中)

What I did to bypass this problem: I upload my string in pieces of less than 4000 characters. 我为避免这个问题所做的工作:我上传的字符串少于4000个字符。 BUT I still face the problem! 但是我仍然面对问题! Every second upload gets cut off and I can't figure out why. 每秒上传的文件都会被切断,我不知道为什么。 This is my C# Code: 这是我的C#代码:

WebClient client = new WebClient();
        foreach (DataRow dr in dra)
        {
            foreach (int y in index)
            {
                data += dr[y] + ";";
                Console.Write(".");
            }
            data += ":";

            if (count1 > 50)
            {
                // Upload the data.
                Console.WriteLine("Uploading Data.....");
                Console.WriteLine("Länge des Strings:" + data.Length);
                Console.WriteLine(data);
                client.Dispose();
                client.Encoding = System.Text.Encoding.UTF8;
                client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                string Ergebnis = client.UploadString(address, "POST", data);
                Console.WriteLine(Ergebnis);
                client.Dispose();
                result.ErrorMessage += Ergebnis;
                count1 = -1;
                data = "table="+table+"&columns=continueUpload&values=";

            }
            ++count1;
        }

Does anyone have any idea where this comes from? 有谁知道这是从哪里来的? Is there any string limit on the webclient method? webclient方法是否有任何字符串限制?

Alright, I found the solution, thanks Alex for the hint! 好了,我找到了解决方案,谢谢亚历克斯的提示! I had to urlencode all my values, than it worked! 我不得不对我所有的价值观进行urlencode,这比它有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM