这是我在应用程序端编写的代码,正在使用Xamarin
开发
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(ApiUrl);
objRequest.Method = "POST";
objRequest.ContentType = "application/x-www-form-urlencoded";//"application/json;charset=utf-8";
objRequest.Headers.Add("Authentication", "web60134");
UTF8Encoding utf8Encoding = new UTF8Encoding();
byte[] arrRequest;
arrRequest = utf8Encoding.GetBytes(JsonReq);
objRequest.ContentLength = arrRequest.Length;
Stream requestStream = objRequest.GetRequestStream();
requestStream.Write(arrRequest, 0, arrRequest.Length);
requestStream.Close();
HttpWebResponse res = (HttpWebResponse)objRequest.GetResponse();
StreamReader streamReader = new StreamReader(res.GetResponseStream());
string result = streamReader.ReadToEnd();
这是在服务器端编写的代码,即PHP
$recvd = $_POST['TH_ET_LoginProcess'];
$recvdArr = json_decode($recvd);
我尝试使用file_get_contents("php://input")
,但这两种方法都返回null或没有。
在这种情况下,使用PHP在Web服务器上读取JSON的最佳方法是什么?