Sunucuya bir metin göndermek ve if(text != null)
yeni metin değerlerini döndürmek için uygulamayı yaratıyorum. Ben sunucusundaki bir dosyayı kaydetmekPHP sunucusundan dize Android'e nasıl geçilir?
$text = $_POST["text1"];
if($text != null){
echo "Contact1-----".$text."-----10h49 25/03/2016 at New York city";
} else{
echo "";
}
Öncesi ve bu dosyaya tüm verileri yazın: PHP Server
:
Benim kod böyle yapmak. Şu anda, Android verisine geri dönmek istiyorum, dosyaya kaydetmeye gerek yok. Ve Android kodu vardır: answer
null
neden bilmiyorum
final String scripturlstring = "http://www.anyexample.com/main.php";
AddContactActivity contact;
public void sendToServer(final String text){
contact = new AddContactActivity();
new Thread(new Runnable() {
@Override
public void run() {
try {
String textparam = "text1=" + URLEncoder.encode(text, "UTF-8");
URL scripturl = new URL(scripturlstring);
HttpURLConnection connection = (HttpURLConnection) scripturl.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setFixedLengthStreamingMode(textparam.getBytes().length);
contentWriter.write(textparam);
contentWriter.flush();
contentWriter.close();
InputStream answerInputStream = connection.getInputStream();
final String answer = getTextFromInputStream(answerInputStream);
if(answer!="") {
String[] contactInfo = answer.split("-----");
contact.insertContact(contactInfo[0], contactInfo[1], contactInfo[2], "", "");
}
answerInputStream.close();
connection.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
public String getTextFromInputStream(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder stringBuilder = new StringBuilder();
String currentLine;
try {
while ((currentLine = reader.readLine()) != null) {
stringBuilder.append(currentLine);
stringBuilder.append("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
return stringBuilder.toString().trim();
}
.
Ben gibi verileri geri dönmelidir düşünüyorum:
Contact1 $text 10h49 25/03/2016 at New York city
kurdu? – Eduard7
@ Eduard7 Hiçbir şey göstermiyor. PHP dosyasında olduğunu düşünüyor musunuz? – vanloc
$ _POST ["text1"] 'i $ _GET ["text1"] ile değiştirmeyi deneyin. – Eduard7