我使用post方法将文件上传到我的服务器。这部分还可以。但它无法正确读取结果。
它必须返回:{" id":" 5" ," url":" http://aaaaaaaa/bnm.jpg"}。
但它返回:64bnm.jpg []。
相关代码段:
public void uploadFile() throws IOException {
Log.i("tago", "PageFragment1 resim gonderme islemi");
HashMap<String, String> postDataParams = new HashMap<>();
postDataParams.put("placeID", nameofChannel);
postDataParams.put("img", image);
postDataParams.put("id", SharedPrefIdAl());
URL url;
String response = "";
try {
url = new URL("http://185.22.187.60/shappy/place_photos/place_picture.php");
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"));
writer.write(getPostDataString(postDataParams));
writer.flush();
writer.close();
os.close();
try {
BufferedReader in;
if (conn.getResponseCode() == 200) {
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputline = in.readLine();
Log.i("tago", "kanal for " + inputline);
JSONArray jsonArray = new JSONArray(inputline);
JSONObject jsonObject = jsonArray.getJSONObject(0);
yenikanalid = jsonObject.optString("id");
yenikanalurl = jsonObject.optString("photo");
Log.i("tago", "kanal for kanalid " + yenikanalid + "kanalurl " + yenikanalurl);
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
}
}
我从logcat读取输入行。为什么会这样?