-1

I'm trying to send large json string in my c# application to an asp.net page using querystring (POST method), but because the string is too long it give me this msg: Invalid uri: the uri link is too long.

Is there is another solution for my problem !?

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();
6
  • 1
    POST data is not part of the URI, so the error doesn't make much sense to me. What does the ASP.NET page do with the POST data? Could the error be there? Commented Jul 20, 2014 at 10:15
  • How about using the WebClient class and one of the WebClient.UploadData overloads instead of the WebRequest class? Commented Jul 20, 2014 at 11:27
  • I might be missing it, but based only on the above, what is querystring? The variable name? The actual query string (of uri)? I see the former (which you seem to be POSTing)..but not the latter... Commented Jul 20, 2014 at 16:02
  • Svick..the error occure in c# page .. before i can send it ! and my querystring is too long .. i check it. i need to send the json string to asp.net page ! Commented Jul 21, 2014 at 5:25
  • I dont see where you are creating you URL. Is the URL the onlineApp variable? There would be no need to create a URL with a querystring if you are POSTing the data. e.g. com?s=querystring. If the API is expecting a POST, it will bring in the data you are writing to the request stream. Commented Feb 7, 2020 at 20:15

1 Answer 1

0

I think your problem in your WebRequest , when you create new Webrequest , check you webrequest string.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.