我從我的android應用程序發送圖像數據到服務器,我可以在日誌中看到該字符串數組不是空的,並具有正確的數據,但在服務器上它收到null。服務器接收空的JSON字符串數組來自android應用
下面是我在哪裏發送數據我的AsyncTask服務器
protected Void doInBackground(Void... params) {
BufferedReader reader;
try {
URL url = new URL("http://www.example.com/Data/galleryLog.php");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
Log.d(TAG,"String Data "+Images);
//For POST Only - Begin
OutputStream os = connection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(Images);
writer.flush();
writer.close();
os.close();
connection.connect();
//For POST Only End
int responseCode = connection.getResponseCode();
Log.d(TAG, "POST RESPONSE CODE " + responseCode);
String LoginResult;
if (responseCode == HttpURLConnection.HTTP_OK) {
//Success
Log.d(TAG, "Success connection with database");
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = reader.readLine()) != null) {
response.append(inputLine);
}
reader.close();
Log.d(TAG, "Reader Close - Printing Result ");
//Print Result
Log.d(TAG, "Calling Response " + response.toString());
}
return null;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
這是我在logcat中得到的字符串,它不是空的,並且具有正確的數據
String Data {"galleryDesc":"My First Gallery","images":[{"base64code":"Base64Image","type":"jpg","imagename":"image-101.jpg"}],"User_ID":"18","galleryTitle":"Image-101.jpg"}
我的PHP代碼中我打印收到的數據到文件,但它給我空白文件總是
<?php
$tm = 'ritu_gallery_'.time().'.log';
file_put_contents($tm, print_r($_POST, TRUE));
echo "Response<br>";
print_r($_POST);
?>
它的創建文本文件,這樣
陣列()
UPDATE:其的AsyncTask字符串數組的問題。我不知道爲什麼它不working.If的人都知道,請讓我知道
當我發送此字符串數組server.it的打印服務器
{"galleryDesc":"My First Gallery","images":[{"base64code":"Base64Image","type":"jpg","imagename":"image-101.jpg"}],"User_ID":"18","galleryTitle":"Image-101.jpg"}
空白值當我添加上面的字符串數組到這個
String data= URLEncoder.encode("Pic","UTF-8")+ "=" +URLEncoder.encode(Images,"UTF-8");
它在這樣
陣列服務器創建文件( [分割] => {「galleryDesc」:「My First Gallery」,「images」:[{「base64code」:「Base64Image」,「type」:「jpg」,「imagename」:「101.jpg」}],「User_ID」 :「18」,「galleryTitle」:「101.jpg」} )
所有正確的值。如果有人知道爲什麼會發生這種情況。請讓我知道
請問如何查看文件在php因爲我不擅長PHP – Ritu
就像你在發佈中一樣,對不起它是$ _FILES。 $ _FILES ['images'] – adam
實際上我複製了一些網站的php代碼。所以我不能修改你說的 – Ritu