发送大型JSON字符串

时间:2014-07-20 10:06:36

标签: c# asp.net json

我正在尝试使用querystring(POST方法)将我的c#应用程序中的大型json字符串发送到asp.net页面,但由于字符串太长,它会给我这个消息:无效的uri:uri链接也是长。

我的问题是否有另一种解决方案!?

if(allRecords.Count > 0)
    for (int j = 0; j < allRecords.Count; j++)
    {
        queryString += JsonConvert.SerializeObject(allRecords[j], Newtonsoft.Json.Formatting.Indented);
    }
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(queryString);

// Set up Request.
HttpWebRequest webReq = WebRequest.Create(onlineApp) as HttpWebRequest;
webReq.ContentType = "text/plain";
webReq.Method = "POST";
webReq.Credentials = CredentialCache.DefaultCredentials;
webReq.ContentLength = data.Length;

// Send Request.


Stream newStream = webReq.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();

// get Response.
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());

string tt = reader.ReadToEnd();

reader.Close();
response.Close();

1 个答案:

答案 0 :(得分:0)

我认为您的WebRequest中的问题,当您创建新的Webrequest时,请检查您的webrequest字符串。