0
我想通過打開的連接發送用戶信息到服務器,它返回JSON中的用戶ID。一切都還好,但是當我試圖用getInputStream讀取用戶ID時,我無法讀取它(我帶500服務器錯誤)。當我用getErrorStream嘗試它並記錄結果時,JSON就來到了這裏。爲什麼?我如何克服它?安卓到服務器500錯誤
public String bilgiyigonder() {
HttpURLConnection connection = null;
try{
Log.i("tago" ,"Veri Tabani bilgiyi gonder" + is.trim());
Log.i("tago" , "Veri Tabani bilgiyi gonder" + urrl);
Log.i("tago" , "VeriTabani bilgiyi gonder" + longi);
Log.i("tago" ,"VeriTabani bilgiyi gonder" + lat);
connection = (HttpURLConnection)new URL("http://185.22.184.103/project/connection.php?name="+URLEncoder.encode("Faarık Fazıl", "ISO-8859-9")+"&url="+urrl+"&long="+longi+"&lat="+lat).openConnection();
Log.i("tago" ,"VeriTabani bagı kurdum");
}catch(IOException e){
e.printStackTrace();
}
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible) ");
connection.setRequestProperty("Accept", "*/*");
connection.setRequestProperty("Accept-Charset", charset);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);
try(OutputStream output = connection.getOutputStream()){
output.write(query.getBytes(charset));
//BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
//while((inputline=in.readLine()) != null){
// Log.i("tago" , inputline);
//}in.close();
//InputStream response = connection.getInputStream();
Log.i("tago", "VeriTabani yazdım");
}catch(IOException e){
e.printStackTrace();
Log.i("tago" , "VeriTabani yazamadım");
}
try {
int status = connection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
String inputline;
while((inputline=in.readLine()) != null){
Log.i("tago" , inputline);
JsondanCevir(inputline);
}in.close();
Log.i("tago" , "VeriTabani status= " +status);
} catch (IOException e) {
e.printStackTrace();
}
return "alabama";
}
500意味着您所使用的服務器是一個那崩潰沒有Android應用 –
根據我研究大多是Tomer,但我的服務器工作的朋友堅持認爲問題與android方面有關。 – Bad0
你的*朋友*不是你的*朋友*。 Tomer說得對。雖然你可能已經構建了一個意想不到的要求,但是沒有關於要求的更多細節,Tomer是對的 – eduyayo