c#webClient上传字符串截断 [英] c# webClient Upload String cuts off
问题描述
我需要有关 C# WebClient UploadString 方法的帮助.我正在尝试将一个长字符串(我从数据库中读取)上传到服务器 (PHP),我目前正在尝试使用 UploadString 方法来做到这一点,因为它似乎是最简单的.我遇到的问题是我上传的字符串在大约 4000 个字符后被切断,我不知道为什么.例如:数据长度:19000(上传前)帖子长度:4000(PHP)
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)
我做了什么来绕过这个问题:我上传了少于 4000 个字符的字符串.但我仍然面临这个问题!每秒上传都会被切断,我不知道为什么.这是我的 C# 代码:
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;
}
有人知道这是从哪里来的吗?webclient 方法是否有任何字符串限制?
Does anyone have any idea where this comes from? Is there any string limit on the webclient method?
推荐答案
好的,我找到了解决方案,感谢 Alex 的提示!我必须对我所有的值进行 urlencode,这才奏效!
Alright, I found the solution, thanks Alex for the hint! I had to urlencode all my values, than it worked!
这篇关于c#webClient上传字符串截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!