Cześć,
dopiero zaczynam PHP i nie wiem czy dobrze się wyrażę ale:
Chce wysłać na serwer plik tekstowy i CHCE to zrobić przez wysłanie stringa a nie pliku. Z tym nie mam problemu. Jednak chce uzyskać odpowiedź od serwera że się udało i z tym tez nie ma problemu. Za pomocą:
String lContent = loadFromFileToString(mDir, mFileName);
HttpClient lHttpClient = new DefaultHttpClient();
HttpPost lPost = new HttpPost("serwer.skrypt.php");
ArrayList<NameValuePair> lArray = new ArrayList<>();
lArray.add(new BasicNameValuePair("content", lContent));
try {
lPost.setEntity(new UrlEncodedFormEntity(lArray, HTTP.UTF_8));
ResponseHandler<String> lResponseHendler = new BasicResponseHandler();
String lResponse = lHttpClient.execute(lPost, lResponseHendler);
Log.d(tag, lResponse);
} catch (Exception e) {
Log.d(tag, e.toString());
}
otrzymuje zawartość pliku ale w odpowiedzi mam całą stronę, a chciałbym tylko krótkiego Stringa "RESPONSE_OK", albo coś podobnego.
kod php:
<?php
$fileContent;
if(isset($_POST['content'])) {
$fileContent = $_POST['content'];
}else{
$fileContent = 'błąd odczytu';
}
$filename = "textFromAndroid.txt";
$file = fopen( $filename, "w" );
if( $file == false )
{
echo ( "Error in opening new file" );
exit();
}
fwrite( $file, $fileContent );
fclose( $file );
echo 'RESPONSE_OK';
?>
Na razie odpowiedź jest w formie:
<html><body><script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/1708342/UGU_PL_StronyUzytkownikow_CSWE_naglowek_728x90', [728, 90], 'div-gpt-ad-1412619226977-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
<div style="display: block; text-align:center; width: 100%; height: 100px;">
<div style="z-index: 99999; text-align:center; margin: 0 auto; padding: 0; width: 728px; height: 90px; display: block; position: relative;">
<script type="text/javascript">
advert = document.getElementsByTagName('body').item(0);
width = advert.clientWidth;
height = advert.clientHeight;
if((parent==self || width>500 && (height>250 || height==0)) ) {
try {
document.write('<div id="div-gpt-ad-1412619226977-0" style="z-index: 100000; position: absolute; top: 0px; left: 0px; width:728px; height:90px;">');
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1412619226977-0'); });
} catch(e) {
document.write('<div style="z-index: 100000; position: absolute; top: 0px; left: 0px;"><a href="http://www.bajkowa-planeta.pl" target="_parent" style="display: block; width: 728px; height: 90px; background: url(http://www.bajkowa-planeta.pl/img/b2.jpg);"></a></div>');
}
document.write('</div>');
};
</script>
</div>
</div>
ďťżďťżďťż<#response_ok#><script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-1665446-6', 'auto');
ga('send', 'pageview');
</script>
</body></html>
a chciałbym krótkie
<#response_ok#>
Nie wiem czy mam szukać innych klas w Javie czy jakoś inaczej wysyłać odpowiedź w PHP, czy to i to. A wydaje mi się że odpowiedź nie jest trudna
Dodam jeszcze że wiem że mogę sobie to umieścić w znacznikach i wyszukiwać tego stringa i na razie tak robię, ale chyba przesyłanie całego kody strony nie jest najlepszym pomysłem