안드로이드에서는,,,
JSONObject send_json = new JSONObject();
중략================================
try {
send_json.put("phone_number", checkPhoneNum);
send_json.put("myname", send_name);
send_json.put("myaddr", send_myaddr);
send_json.put("myage", send_myage);
send_json.put("mysex", send_mysex);
send_json.put("myjob",send_myjob);
send_json.put("mymemo", send_mymemo);
send_json.put("myagree", send_myagree);
send_json.put("image",imageEncode);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// TODO Auto-generated method stub
}
//내부에서 하는 작업
@SuppressWarnings("null")
@Override
protected Void doInBackground(Void... params) {
final String URL = "http://서버주소/modifyUserInfor.jsp";
String postPara= send_json.toString();
Log.d("보내기전 제이슨값", postPara); //값 출력됨
URL url = null;
HttpURLConnection conn = null;
PrintWriter postReq = null;
BufferedReader postRes = null;
StringBuilder json = null;
String line = null;
json = new StringBuilder();
try {
url = new URL("URL);
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "text/plain");
conn.setRequestProperty("Content-Length", Integer.toString(postPara.length()));
conn.setDoInput(false);
postReq = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8"));
postReq.write(postPara);
postReq.flush();
========================
jsp 문서에서는
JSONObject jsonObject=null;
String phone_num =null;
String name = null;
String address = null;
int myage =0;
String mysex =null;
String myjob = null;
String mymemo =null;
String myagree = null;
String myphoto = null;
byte[] b1={0};
//byte[] qrimageBytes;
StringBuffer jb = new StringBuffer();
//StringBuilder jb = new StringBuilder();
String line = null;
try{
BufferedReader reader = request.getReader();
while((line = reader.readLine())!=null)
jb.append(line);
}catch(Exception e){
e.printStackTrace();
}
try{
jsonObject = JSONObject.fromObject(jb.toString());
phone_num = jsonObject.getString("phone_number");
name = jsonObject.getString("myname");
address = jsonObject.getString("myadd");
myage = jsonObject.getInt("myage");
mysex = jsonObject.getString("mysex");
myjob = jsonObject.getString("myjob");
mymemo = jsonObject.getString("mymemo");
myagree = jsonObject.getString("myagree");
myphoto = jsonObject.getString("myimage");
//qrimageBytes = Base64.decode(myphoto.getBytes(), 0);
BASE64Decoder decoder = new BASE64Decoder();
b1 = decoder.decodeBuffer(myphoto);
}catch(Exception e1){
}
try{
SQL= "update user_infor set name=?,address=?,age=?,sex=?,job=?,memo=?,agree=?,image=? where phone_number = ?";
pstmt = con.prepareStatement(SQL);
pstmt.setString(1,name);
pstmt.setString(2,address);
pstmt.setInt(3, myage);
pstmt.setString(4,mysex);
pstmt.setString(5,myjob);
pstmt.setString(6,mymemo);
pstmt.setString(7,myagree);
pstmt.setBytes(8, b1);
pstmt.setString(9, phone_num);
pstmt.executeUpdate();
} catch(Exception e){
e.printStackTrace();
}
==============
여기서 질문 있습니다. 현재 안드로이드에서 서버측으로 post data가 넘어가는 코딩부분이 맞나요??
넘어가는 것을 서버측에서 어떻게 확인해야하나요?? 실시간으로 알수 있을가요??
서버측 JSP가 문제인지 안드로이드가 문제인지 모르겠습니다. 조언좀 부탁드립니다.
현재까지 GET방식만 쓰다가 image 파라미터의 길이가 커서 post방식으로 바꾸었는데 post방식은 잘 모르겠네요,.ㅠㅠ
postReq = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8"));
postReq.write(postPara);
postReq.flush();
postRes = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
while ((line = postRes.readLine()) != null){
json.append(line);
}
conn.disconnect();
현재 글은 중략해서 쓴 글이며, 아래 부분은 위와 같습니다. 그런데도 데이터를 안넘겨주네요.ㅠㅠ
웹서버 접근하실때, streamwrite 후에 flush 하시고 아무 작업도 안하시나요?
그럼 단지 아웃스트림에 데이터만 기록했을뿐 웹서버의 접속하는 일은 하지 않습니다.
write 한 후에 "반드시"
getResponseCode() 메서드 혹은 inputstream 으로 read 작업을 하셔야 웹서버에 데이터를 전달하는 작업을 시작합니다.
웹쪽은 잘아는 편이 아니라.. 서버에서 어떻게 확인해야하는지는 모르겠으나..
저같은 경우에는 항상 데이터를 준후에 리턴값을 웹페이지에 출력해서 안드로이드가 읽어온후 확인하던가,
getResponseCode() 의 리턴값을 확인해서 동작 여부를 판단 하곤 합니다.