HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(15000); conn.setConnectTimeout(15000); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); OutputStream os = conn.getOutputStream(); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(os, "UTF-8")); String paramStr = null; {// need BasicNameValuePair -> ContentsValue for(BasicNameValuePair record : params){ if(paramStr == null){ paramStr = ""; }else{ paramStr = paramStr + "&"; } paramStr = paramStr + record.getName()+"="+record.getValue(); } } writer.write(paramStr); writer.flush(); writer.close(); os.close(); int responseCode=conn.getResponseCode(); if (responseCode == HttpsURLConnection.HTTP_OK) { String line; BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((line=br.readLine()) != null) { response+=line; } } else { response=""; throw new HttpException(responseCode+""); } } catch (Exception e) { e.printStackTrace(); }
ref : http://stackoverflow.com/questions/9767952/how-to-add-parameters-to-httpurlconnection-using-post
댓글
댓글 쓰기