0

we are using a web service which receives JSON payloads and sends back JSON payloads as response. I know how to do it c#, but unfortunately it doesn't seem easy doing the same thing in PHP. here is our c# code, what is the equivalent piece of PHP code of this??

        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\": \"[email protected]\"";
        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();
0

1 Answer 1

0

Look at using the json_encode function. It will take an array and generate a JSON string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.