Answer the question
In order to leave comments, you need to log in
Problem with saving Json data in PhP?
Sending data as json string to PHP server. The server sees them and creates a file for them, but does not save them, the server also gives an answer. Since I am a complete zero in PHP, I would like to get help, your help. So why doesn't the server save the data?
Here is the processing code:
<?php
$r = $_POST['req'];
$fn = fopen('reqest.txt','a+');
fwrite($fn, $r);
fclose($fn);
$arr = array('status'=>ok,'code'=>2,'monitor_frequency'=>2);
// $test = array();
echo json_encode($arr);
?>
static String SendJsonViaPost(String url, String json) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
try {
// StringEntity stringEntity = new StringEntity(json, "UTF-8");
//stringEntity.setContentType("application/json");
//post.setEntity(stringEntity);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("uid",m_szUniqueID));
nameValuePairs.add(new BasicNameValuePair("data",json));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
responseJson += line;
}
} catch (IOException e) {
e.printStackTrace();
}
return responseJson;}
Answer the question
In order to leave comments, you need to log in
Do it like this
<?php
$r = $_POST['req'];
var_dump($r);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question