-2
PHP를 사용하여 안드로이드에서 웹 서비스로 JSONObject로 이미지 (base64로 압축 된 이미지)를 업로드하려고합니다. 메서드 게시와 함께 HttpURLConnection을 사용하려고했습니다.안드로이드에서 웹 서비스 PHP로 이미지 업로드 json (base64로 압축)
내 코드, android.
내가 가진 로그 캣에서try {
JSONObject params = new JSONObject();
params.put("nombre", name);
params.put("img", imgBase64);
Log.d("params", params.toString());
URL url = new URL(urlServer);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
//conn.setReadTimeout(5000);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
BufferedOutputStream BuffOut = new BufferedOutputStream(conn.getOutputStream());
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(BuffOut, "UTF-8"));
writer.write(params.toString());
writer.close();
BuffOut.close();
//open
conn.connect();
//do somehting with response
int responseCode = conn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader buffr = new BufferedReader(new
InputStreamReader(
conn.getInputStream()));
StringBuffer sb = new StringBuffer("");
String line = "";
while ((line = buffr.readLine()) != null) {
sb.append(line);
break;
}
Log.d("leer", sb.toString());
buffr.close();
conn.disconnect();
return sb.toString();
} else {
Log.d("err","false : " + responseCode);
return "false : " + responseCode;
}
} catch (JSONException e) {
return " Exception JSON: " + e.getMessage();
} catch (IllegalStateException e) {
return " IllegalStateException: " + e.getMessage();
} catch (UnsupportedEncodingException e) {
return " UnsupportedEncodingException: " + e.getMessage();
} catch (ProtocolException e) {
return " ProtocolException: " + e.getMessage();
} catch (MalformedURLException e) {
return " MalformedURLException: " + e.getMessage();
} catch (IOException e) {
return " Exception IO: " + e.getMessage();
} catch (Exception e) {
return " Exception: " + e.getMessage();
}
같은 오류 : 내가 가지고있는 서버 측에서 스트림
의 예기치 않은 종료, PHP : ProtocolException 사용
header('Content-type: application/json');
if($_SERVER['REQUEST_METHOD'] == "POST"){
if(!empty($_POST['nombre'])&&!empty($_POST['img'])){
echo json_encode(array('status' => 'ok', 'msg' => "hi ".$_POST['nombre']. " img ".$_POST['img']));
}
}
'BufferedWriter reader'??? 네 이름이 괜찮다고 생각하니? – greenapps
LogCat을 해당 예외를보고 싶은대로 게시하십시오. – greenapps
'BufferedOutputStream inB'? 에서? – greenapps