It is easy to use Java to implement cross-origin access. It turns out that the Java net package can be used to implement connection URL, post, get value or something.
Of course, you can also use a third-party method like httpclient.
The problem encountered today is that an exception occurs during post:
Java. Io. ioexception: server returned HTTP response code: 500 for URL: http: // 192.98.8.50 /...
I checked it on the Internet, which is also a lot of situations,
I encountered the following problems:
I opened outputstreamwriter without the post parameter.
The modified complete program is as follows:
Private stringbuffer urlconnectionpost (string tourl, stringbuffer data) {<br/> stringbuffer sb = NULL; <br/> bufferedreader reader = NULL; <br/> outputstreamwriter wR = NULL; <br/> URL; <br/> try {<br/> url = new URL (tourl); <br/> urlconnection conn = URL. openconnection (); <br/> Conn. setdooutput (true); <br/> Conn. setconnecttimeout (1000*5); <br/> // enable outputstreamwriter only when there is a post value <br/> If (dat A! = NULL & data. tostring (). trim (). length ()> 0) {<br/> wR = new outputstreamwriter (Conn. getoutputstream (), "UTF-8"); <br/> Wr. write (data. tostring (); <br/> Wr. flush (); <br/>}</P> <p> // get the response <br/> reader = new bufferedreader (New inputstreamreader (conn <br/>. getinputstream (), "UTF-8"); <br/> Sb = new stringbuffer (); <br/> string line = NULL; <br/> while (line = reader. readline ())! = NULL) {<br/> Sb. append (LINE + "/N"); <br/>}< br/>} catch (ioexception E) {<br/> // todo auto-generated Catch Block <br/> E. printstacktrace (); <br/>}finally {<br/> try {<br/> If (WR! = NULL) {<br/> Wr. Close (); <br/>}< br/> If (reader! = NULL) {<br/> reader. close (); <br/>}< br/>} catch (ioexception e) {<br/> // todo auto-generated Catch Block <br/> E. printstacktrace (); <br/>}< br/> return sb; <br/>}