| 43 | } |
| 44 | |
| 45 | public static String postGeneralUrl(String generalUrl, String contentType, String params, String encoding) |
| 46 | throws Exception |
| 47 | { |
| 48 | //����URL |
| 49 | URL url = new URL(generalUrl); |
| 50 | //����HttpURLConnection |
| 51 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| 52 | connection.setRequestMethod("POST"); |
| 53 | //����Content-Type |
| 54 | connection.setRequestProperty("Content-Type", contentType); |
| 55 | //����������Ϣ |
| 56 | connection.setRequestProperty("Connection", "Keep-Alive"); |
| 57 | connection.setUseCaches(false); |
| 58 | |
| 59 | connection.setDoOutput(true); |
| 60 | connection.setDoInput(true); |
| 61 | //���������������� |
| 62 | DataOutputStream out = new DataOutputStream(connection.getOutputStream()); |
| 63 | out.write(params.getBytes(encoding)); |
| 64 | out.flush(); |
| 65 | //�ر� |
| 66 | out.close(); |
| 67 | //���� |
| 68 | connection.connect(); |
| 69 | //�������ͷ��ӡ���� |
| 70 | Map<String, List<String>> headers = connection.getHeaderFields(); |
| 71 | for (String key : headers.keySet()) { |
| 72 | System.err.println(key + "--->" + headers.get(key)); |
| 73 | } |
| 74 | |
| 75 | BufferedReader in = null; |
| 76 | //�õ���� |
| 77 | in = new BufferedReader(new InputStreamReader(connection.getInputStream(), encoding)); |
| 78 | String result = ""; |
| 79 | String getLine; |
| 80 | //�����ȡ���� |
| 81 | while ((getLine = in.readLine()) != null) { |
| 82 | result += getLine; |
| 83 | } |
| 84 | in.close(); |
| 85 | //�������ӡ���������ؽ�� |
| 86 | System.err.println("result:" + result); |
| 87 | //���ؽ�� |
| 88 | return result; |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * @ |