c# webClient Upload String cuts off

谁说我不能喝 提交于 2020-01-06 03:40:11

问题


I need some help with the C# WebClient UploadString Method. 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. 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. For Example: data.length: 19000 (before Upload) Post.length: 4000 (in PHP)

What I did to bypass this problem: I upload my string in pieces of less than 4000 characters. BUT I still face the problem! Every second upload gets cut off and I can't figure out why. This is my C# Code:

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?


回答1:


Alright, I found the solution, thanks Alex for the hint! I had to urlencode all my values, than it worked!



来源:https://stackoverflow.com/questions/26778191/c-sharp-webclient-upload-string-cuts-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!