Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2502
  • Last Modified:

C# WebResponse Error 414

My application sends xml file with WebRequest and WebResponse. With GetResponse I ger Exception
System.Net.WebException: The remote server returned an error: (414) Request-URI Too Long

File is 22k and short file works OK.
I know with java following works:
  var xmlServerHttp = new ActiveXObject("Msxml2.ServerXMLHTTP.3.0");
...
 xmlServerHttp.setOption(2, "13056"); // SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS

Has somebody ideas with .NET?

0
ziiffi
Asked:
ziiffi
  • 5
  • 4
1 Solution
 
ChetOS82Commented:
It looks like you are trying to send the xml file as part of the URI (GET method).  Try using POST method instead, it is only slightly more complicated.
0
 
ziiffiAuthor Commented:

This is the exact way I use. Response is needed to check the result.

WebRequest wr;
WebResponse res;

wr = WebRequest.Create(url);
wr.Proxy = GlobalProxySelection.GetEmptyWebProxy();
wr.Method = "POST";
wr.ContentType = "multipart/form-data";

bytes = System.Text.Encoding.GetEncoding("iso-8859-1") .GetBytes (url);
wr.ContentLength = bytes.Length;
Stream os = wr.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();

res = wr.GetResponse();
Stream rs = res.GetResponseStream();
StreamReader rr = new StreamReader(rs, System.Text.Encoding.GetEncoding("iso-8859-1"));
result = rr.ReadToEnd();
0
 
ChetOS82Commented:
"multipart/form-data" is an encoding type, not a content type.  You should use "application/x-www-form-urlencoded" for the content type.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
ziiffiAuthor Commented:
Same error result with this.
0
 
ChetOS82Commented:
Ok, after closer examination, I see the "url" variable, and then you try to send the "url" variable as the content of the POST.  Does "url" contain the address or the content to be sent?  What is the length in "bytes.Length"?
0
 
ziiffiAuthor Commented:
Yes, it contains, and the length of bytes is 22436. This works with shorter messages

This message anf longer works with java and there is used Ignore error option.
0
 
ChetOS82Commented:
Ok, well you cannot have a URI that is that long.  That isn't how POST method works anyway.  You need to set the URL to just the URL, and have another variable which contains the actual data.  If you prefix the data with something like "data=", then you can retrieve the form data using Request.Form("data").
0
 
ziiffiAuthor Commented:
OK. This is the point: separate url and data. Seems much better, Thanks
0
 
ziiffiAuthor Commented:
No more errors, I will finalize this tomorrow because remote database is off, However I got remote info message
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now