9a328c021fbc0d270bbc83eb470a9665459dbe16.svn-base 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package xin.glue.user.common;
  2. import javax.net.ssl.HttpsURLConnection;
  3. import com.alibaba.fastjson.JSON;
  4. import java.io.BufferedReader;
  5. import java.io.DataOutputStream;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.io.InputStreamReader;
  9. import java.io.OutputStreamWriter;
  10. import java.net.HttpURLConnection;
  11. import java.net.URI;
  12. import java.net.URISyntaxException;
  13. import java.net.URL;
  14. import java.net.URLConnection;
  15. public class UIJ030054 {
  16. public HttpURLConnection createConnection(URI uri) throws IOException {
  17. URL url = uri.toURL();
  18. URLConnection connection = url.openConnection();
  19. HttpsURLConnection httpsURLConnection = (HttpsURLConnection) connection;
  20. httpsURLConnection.setSSLSocketFactory(new UIJ030053());
  21. return httpsURLConnection;
  22. }
  23. public static void main(String[] args) {
  24. UIJ030052 uij030052 = new UIJ030052();
  25. String cod1,cod2;
  26. String asd=uij030052.jsonPost("http://172.16.0.49/xg56/webservice/mesWaybillService/queryIsLock/20181213S268", "20181204S116");
  27. int loc=asd.indexOf("IS_LOCK");
  28. int loc1=asd.indexOf("RET_CODE");
  29. cod1=asd.substring(loc1+11, loc1+12);
  30. cod2=asd.substring(loc+10, loc+11);
  31. UIJ030054 httpsUrlConnectionMessageSender = new UIJ030054();
  32. String loginUrl = "https://218.87.96.132/xg56/webservice/mesWaybillService/queryIsLock/20181127S010";
  33. //String data = "username=xiaomi&password=Ultrasafe_123";
  34. HttpURLConnection connection;
  35. try {
  36. connection = httpsUrlConnectionMessageSender.createConnection(new URI(loginUrl ));
  37. connection.setDoOutput(true);
  38. connection.setDoInput(true);
  39. connection.setRequestMethod("POST");
  40. connection.setUseCaches(false);
  41. connection.setInstanceFollowRedirects(true);
  42. connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  43. connection.connect();
  44. //POSTÇëÇó
  45. OutputStreamWriter os = null;
  46. String json="";
  47. // os = new OutputStreamWriter(connection.getOutputStream());
  48. // os.write(data);
  49. // os.flush();
  50. json=getResponse(connection);
  51. System.out.println(json);
  52. if (connection != null) {
  53. connection.disconnect();
  54. }
  55. } catch (IOException e) {
  56. // TODO Auto-generated catch block
  57. e.printStackTrace();
  58. } catch (URISyntaxException e) {
  59. // TODO Auto-generated catch block
  60. e.printStackTrace();
  61. }
  62. }
  63. public static String getResponse(HttpURLConnection Conn) throws IOException {
  64. InputStream is;
  65. if (Conn.getResponseCode() >= 400) {
  66. is = Conn.getErrorStream();
  67. } else {
  68. is = Conn.getInputStream();
  69. }
  70. String response = "";
  71. byte buff[] = new byte[512];
  72. int b = 0;
  73. while ((b = is.read(buff, 0, buff.length)) != -1) {
  74. response += new String(buff, 0, b);
  75. }
  76. is.close();
  77. System.out.println(response);
  78. return response;
  79. }
  80. }