You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »


When call RESTful API containing JSON data in the body, server needs to take its content, but getting it by parameters may have some restrictions like data length or etc. To avoid that error, the easiest way can do it will be taking it from entity body directly. file_get_contents('php://input') will help you to solve it easily.

Below example is what I tested in PHP.


Let us assume we need to call following calling method:

curl -n -X POST 'http://magic.its-newid.net/api_test.php' -H 'Token: {blabhlbah}' -H 'Accept: text/xml, application/xml, application/json' -H 'Content-Type: application/json' -d '{"channels":[{"channelId":"gentleman","channelName":"NEW K.ID","channelNumber":"511","logoUrl":"https:\/\/static.foo.com\/media\/fbfaux1c4d578f426943e0b1d94f81bfb18fce~mv2.png","logoWidth":100,"logoHeight":50,"channelGenreCode":"62","adultFlag":false,"paidFlag":false,"adFlag":true,"tmsFlag":false,"promotionFlag":true,"contact":"+821025268644","resolution":"FHD","channelType":"VOD","streamContainerType":"MPD","regionList":[{"countryCode":"GB","countryRegionCode":"all"},{"countryCode":"DE","countryRegionCode":"all"},{"countryCode":"FR","countryRegionCode":"all"},{"countryCode":"ES","countryRegionCode":"all"},{"countryCode":"IT","countryRegionCode":"all"}],"activeTimePeriodStart":"2020-07-31T00:00:00Z","activeTimePeriodEnd":"2029-07-31T00:00:00Z","visible":true,"deviceList":[{"deviceName":"LG_TV","deviceVersion":"all"}],"relatedProgramIdList":[{"programId":"5db2aae1df86dve35c177ac97b"},{"programId":"5e40c1a6se703a05000158d6df"},{"programId":"5e4b39cd5f3f57d0001e90d55"},{"programId":"5e45ec51fbfb400001e49664"},{"programId":"5dc9f3eb70d7635e200ee83d"},{"programId":"5db4ceafee0dda95bec1af4ae"},{"programId":"5e40a997f742bb00018d2657"},{"programId":"5e4202c07628b30001f987eb"},{"programId":"5e4e1d675f3f570001e93be9"},{"programId":"5e4a67c82f6eaf000119bea8"},{"programId":"5e4ca3a12f6eaf000119d9f9"},{"programId":"5e3b78f02837c1500013d0f42"},{"programId":"5e4a589b2f6eafx000119be12"},{"programId":"5e4ba3cd5fb3f570001e915d4"},{"programId":"5e4e1c2e2f6eaf000119ef42"},{"programId":"5e4e171b5fd3f570001e93a3e"},{"programId":"5e3d26c1e70305000158b539"},{"programId":"5e466614b1c387000109330c"}]},{"channelId":"newid_002","channelName":"MUKBANG","channelNumber":"12","logoUrl":"https:\/\/static.wixstatic.com\/media\/fbfe8c_4d161de9f09142788ce4059a837e7bd0~mv2.png","logoWidth":100,"logoHeight":50,"channelGenreCode":"57","adultFlag":false,"paidFlag":false,"adFlag":true,"tmsFlag":false,"promotionFlag":true,"contact":"+821025268644","resolution":"FHD","channelType":"VOD","streamContainerType":"MPD","regionList":[{"countryCode":"GB","countryRegionCode":"all"},{"countryCode":"DE","countryRegionCode":"all"},{"countryCode":"FR","countryRegionCode":"all"},{"countryCode":"ES","countryRegionCode":"all"},{"countryCode":"IT","countryRegionCode":"all"}],"activeTimePeriodStart":"2020-07-31T00:00:00Z","activeTimePeriodEnd":"2029-07-31T00:00:00Z","visible":true,"deviceList":[{"deviceName":"TV","deviceVersion":"all"}],"relatedProgramIdList":[]},{"channelId":"newid_003","channelName":"PBATour","channelNumber":"13","logoUrl":"https:\/\/static.wixstatic.com\/media\/fbfe8c_b23be6440003417e8591b7db10ece72d~mv2.png","logoWidth":100,"logoHeight":50,"channelGenreCode":"23","adultFlag":false,"paidFlag":false,"adFlag":true,"tmsFlag":false,"promotionFlag":true,"contact":"+821025268644","resolution":"FHD","channelType":"VOD","streamContainerType":"MPD","regionList":[{"countryCode":"GB","countryRegionCode":"all"},{"countryCode":"DE","countryRegionCode":"all"},{"countryCode":"FR","countryRegionCode":"all"},{"countryCode":"ES","countryRegionCode":"all"},{"countryCode":"IT","countryRegionCode":"all"}],"activeTimePeriodStart":"2020-07-31T00:00:00Z","activeTimePeriodEnd":"2029-07-31T00:00:00Z","visible":true,"deviceList":[{"deviceName":"TV","deviceVersion":"all"}],"relatedProgramIdList":[]},{"channelId":"newid_004","channelName":"MUSIC&NEW","channelNumber":"14","logoUrl":"https:\/\/static.wixstatic.com\/media\/fbfe8c_d821c776b7cc40cba4ab3e0e4594572b~mv2.png","logoWidth":100,"logoHeight":50,"channelGenreCode":"18","adultFlag":false,"paidFlag":false,"adFlag":true,"tmsFlag":false,"promotionFlag":true,"contact":"+821025268644","resolution":"FHD","channelType":"VOD","streamContainerType":"MPD","regionList":[{"countryCode":"GB","countryRegionCode":"all"},{"countryCode":"DE","countryRegionCode":"all"},{"countryCode":"FR","countryRegionCode":"all"},{"countryCode":"ES","countryRegionCode":"all"},{"countryCode":"IT","countryRegionCode":"all"}],"activeTimePeriodStart":"2020-07-31T00:00:00Z","activeTimePeriodEnd":"2029-07-31T00:00:00Z","visible":true,"deviceList":[{"deviceName":"TV","deviceVersion":"all"}],"relatedProgramIdList":[{"programId":"5e4e1c045f3f570001e93b94"},{"programId":"5e4e1bc110726e0001cd3853"},{"programId":"5e4e1c115f3f570001e93b98"},{"programId":"5e4e1c3d2f6eaf000119ef46"},{"programId":"5e4e1c4310726e0001cd385f"},{"programId":"5e4e1c2f5f3f570001e93ba0"},{"programId":"5e4ca2585f3f570001e924d9"}]}]}'


And below server example will take the JSON body:

<?php

$entityBody = file_get_contents('php://input'); 
echo "STDIN\n\n" . $entityBody . "\n\n";

?>


  • No labels