When the data is transmitted through the WebRequest post, if the parameter in the URL contains '% ', the null pointer or error occurs when the parameter of the address bar is taken. such as the following child
string URL = Http://127.0.0.1/file.do;
String postdata = "domethod=list&content=30%";
byte[] data = Encoding.Default.GetBytes (postdata);
HttpWebRequest myrequest = (HttpWebRequest) webrequest.create (URL);
Myrequest. method = "POST";
Myrequest. ContentType = "application/x-www-form-urlencoded";
Myrequest. ContentLength = data. Length;
Stream stream = Myrequest. GetRequestStream ();
Send data
Stream. Write (data, 0, data. Length);
Stream. Close ();
Get response
HttpWebResponse response = (HttpWebResponse) myrequest. GetResponse ();
StreamReader reader = new StreamReader (response. GetResponseStream (), encoding.default);
From the example above, we see that the value of the content is 30%, then the parameter values obtained in the Java servlet after the run are null, which means that the% here is escaped, so how to solve it. We can go ahead and find out what the next hundred semicolon escapes. As follows:
String sss = Urlencoder.encode ("%%%", "GBK");
SYSTEM.OUT.PRINTLN (SSS);
In the console print is%25%25%25, from the results above you can see that the percent of the escape character is%25, then we just need to replace the content in the above example of the% to%25 to solve the problem.