gpt4 book ai didi

android - json对象发布到android应用程序中的php脚本

转载 作者:太空狗 更新时间:2023-10-29 12:46:10 24 4
gpt4 key购买 nike

我试过这个 android 代码将 json 对象发送到我的网站

HttpPost httppost = new HttpPost(url);

JSONObject j = new JSONObject();
j.put("name","name ");

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
String format = s.format(new Date());
nameValuePairs.add(new BasicNameValuePair("msg",j.toString() ));

httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);

还有这段 php 代码

<?php

$msg=$_POST["msg"];

$filename="androidmessages.html";

file_put_contents($filename,$msg."<br />",FILE_APPEND);

$androidmessages=file_get_contents($filename);

echo $androidmessages;
?>

它会显示 {"name":"name "}但如果我使用

httppost.setHeader( "Content-Type", "application/json" );

它不会显示任何内容。我之前没有关于 json 对象帖子的经验,但我认为出了点问题。我想将一些用户信息发送到我的网站并在网页中显示,你能告诉我我需要更改什么吗克服这个问题谢谢

最佳答案

终于找到答案了

$msg=json_decode(file_get_contents('php://input'), true); 

$filename="androidmessages_json.html";

file_put_contents($filename,$msg['name']."<br />",FILE_APPEND);

$androidmessages=file_get_contents($filename);

echo $androidmessages;

关于android - json对象发布到android应用程序中的php脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17896232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com