Home > Back-end >  PostMethod return values are not all questions for help
PostMethod return values are not all questions for help

Time:12-01

Package is introduced: the Commons - the codec - 1.5. The jar, Commons httpclient - 3.0.1. Jar, httpcore - 4.2.4. Jar

HttpClient client=new HttpClient ();
The String url="http://localhost:8089/public/getNameLists? EntpName entpName="+ +" & amp; OrgCode="+ +" orgCode & amp; TypeCode="+ +" typeCode ";
System. The out. Println (" data connection url: "+ url);
Client. GetHttpConnectionManager (.) getParams () setConnectionTimeout (5000);//connection timeout for 5 seconds
Client. GetHttpConnectionManager (.) getParams () setSoTimeout (5000);//read timeout
PostMethod PostMethod=new PostMethod (url);
PostMethod. SetRequestHeader (" the content-type ", "application/json");

//set the parameters of the code for utf-8
PostMethod. GetParams (.) setParameter (HttpMethodParams HTTP_CONTENT_CHARSET, "utf-8");

Try {
//read content
Int status=client. ExecuteMethod (postMethod);

If (postMethod. GetStatusCode ()==HttpStatus. SC_OK) {

BufferedReader reader=new BufferedReader (new InputStreamReader (postMethod. GetResponseBodyAsStream ()));
StringBuffer StringBuffer=new StringBuffer ();
String str="";
While ((STR=reader. ReadLine ())!=null) {
StringBuffer. Append (STR);
}
A String of HTML=stringBuffer. ToString ();
System. The out. Println (" return to the data: "+ HTML);

}
} the catch (Exception e) {
e.printStackTrace();
} the finally {
//release connection
PostMethod. ReleaseConnection ();
}

Print results: return to the data: {" result ":" 1 ", "tableName" : "major cases of the tax law,"}
Correct results: {" result ":" 1 ", "tableName" : "big tax illegal cases, revoked for industry and commerce enterprise list,"} the lack of a value in the tableName, excuse me what happened, because the project is used in a lot of places in the package, so don't want to change, if not, please replace the jar package there is no other solution,,

CodePudding user response:

List major tax illegal cases, revoked for industry and commerce enterprise among the two sentences have Spaces, such as a new line. ReadLine () read into the blank space will stop a line,
  • Related