我们正在使用一个Web服务,它接收JSON有效负载并将JSON有效负载作为响应发回。我知道怎么做c#,但遗憾的是在PHP中做同样的事情似乎并不容易。这是我们的c#代码,这个PHP代码的等价部分是什么?
String str = "https://thewebservice.com";
str += "?schema=1.0";
str += "&form=json";
str += "&token=securedtoken";
str += "&account=38939";
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(str);
req.Method = "POST";
string strRequest = "";
strRequest += "{";
strRequest += "\"$xml\": {";
strRequest += "\"plu$user\": \"http://xml.type.com/User\"";
strRequest += "},";
strRequest += "\"plu$userName\": \"Mia\",";
strRequest += "\"plu$password\": \"secret\",";
strRequest += "\"plu$fullName\": \"Mia Jones\",";
strRequest += "\"plu$email\": \"mia@myisp.com\"";
strRequest += "}";
req.ContentLength = strRequest.Length;
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
while (!streamIn.EndOfStream)
Response.Write(streamIn.ReadToEnd());
streamIn.Close();