Bir PHP sunucusuna bir JSON dizesi göndermeye çalışıyorum, ancak sunucu tarafında hiçbir şey olmuyor. İşte java http gönderi php sunucusuna, hiçbir şey olmuyor
sunucu kodu:<?php
$json = $_POST['json'];
$decoded = json_decode($json);
echo($decoded);
?>
Ve burada JAVA kodu:
public void sendError(Error e)
{
String json = e.toJSONString();
try
{
if(url == null)
{
url = new URL("http://www.rstougaard.dk/errorHandler");
}
if(conn == null)
{
conn = (HttpURLConnection) url.openConnection();
}
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
conn.setRequestProperty("json", URLEncoder.encode(json));
output = new DataOutputStream(conn.getOutputStream());
conn.connect();
output.writeBytes("json=" + URLEncoder.encode(json, "UTF-8"));
output.flush();
BufferedReader input = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while(input.ready())
{
System.out.println(input.readLine());
}
System.out.println(conn.getResponseCode() + " " + conn.getResponseMessage());
} catch (MalformedURLException ex)
{
Logger.getLogger(ConnectionController.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException exc)
{
Logger.getLogger(ConnectionController.class.getName()).log(Level.SEVERE, null, exc);
}
}
.getResponseCode() ve .getResponseMessage() döner '200' ve sırasıyla 'Tamam' . Ve inputStream sadece php kodunu siteden izler ve JSON dizesini izler, bu da bana tuhaf geliyor.
Buraya ne gelmiyorum?
DÜZENLEME
Hala .setResponseMethod içinde POST "() "GET". Ama hiç bir çalışma değişti.
Ben kıvırmak kullanarak denedi
DÜZENLEME kontrol etmek sunucu yanıtı, ama benim java kodunda inputStream ile aynı şey.Onun cevap vermek yerine web sitesinden html/php kodunu basar.
Servis tarafınızı curl ile test ettiniz mi? –
Sunucu günlüklerini kontrol ettiniz mi? – m02ph3u5
Yarından önce sunucu günlüklerine hiç erişimim yok. one.com alanımı barındıranlar ve aparrantly sahiplerinin kendi günlük dosyalarına erişim izni vermezler .... :( – Pogoe