php


Wrong communication in web server using php(REST API)


I sent the JSON message to my web server using POST in postman. But the echo shows only GET and no message. I think the echo should show POST not GET. And the below code is working but the format is not JSON. Please see the image below:
<html>
<head></head>
<body>
<?php
$method = $_SERVER['REQUEST_METHOD'];
$url = 'http://115.145.163.244:5851/TEST52.php';
echo $method;
echo "<br />\n";
switch ($method) {
case 'POST':
$input = json_decode(file_get_contents('php://input'), true);
break;
case 'GET':
$input = json_decode(file_get_contents('php://input'), true);
break;
case 'PUT':
$input = json_decode(file_get_contents('php://input'), true);
break;
case 'DELETE':
$input = json_decode(file_get_contents('php://input'), true);
break;
}
echo ($input->data->ContextID); //it does not work
print_r($input); //it does work. But not in JSON format
?>
</body>
json_decode() converts JSON into array. Therefore if you want to save JSON value to your variable $input use json_encode() instead and if it's already in JSON, you don't have to parse it at all.

Related Links

Dont round integer when pulling from MySql [duplicate]
Wordpress: Creating a dynamic checkbox group using a post loop in functions.php
Undefined index error in php login-registration form [duplicate]
Does nginx fastcgi_pass support variables?
PHP7 language support for PhpStorm
Does file_get_contents() increase bandwidth usage?
PHP $_REQUEST server setting
Android - Retrieving data from remote Database efficiently
What is the advantage of using the LIKE clause in mysql
Is there anyway to add condition in function of parameters?
Getting the most recent rows in mysql
How do I make my url to look nicer?
How to add Buy Now button in cs-cart
PHP conditional assistance
PHP: Error :Syntax to be user near '='a_name','='another_name' at line 1
File not saving in images directory

Categories

HOME
google-chrome
seedstack
code-formatting
initialization
typeerror
mathematical-optimization
iptables
jint
repair
supercollider
gprs
tweepy
driver
migrate
business-intelligence
android-externalstorage
sql-injection
django-rq
synthesis
significance
raml
adminlte
pe
el
altium-designer
raima
gravity-forms-plugin
ccavenue
miniprofiler
ninject
fatfs
nsmutablearray
kendo-listview
advanced-filter
serversocket
creation
android-canvas
nppexec
llvm-ir
right-click
expandablelistview
code-push
wysihtml5
.net-micro-framework
hibernate-ogm
node-apn
sonatype
mura
htmlspecialchars
algebra
gnome-terminal
portability
case-when
dynamics-crm-4
mpmovieplayercontroller
wildfly-9
petsc
p6spy
raw-sockets
cdo.message
processor
taco
trust
wif4.5
html.actionlink
http.client
asp.net-web-api-helppages
blank-line
mutators
ildasm
relationships
webautomation
nachos
commenting
meteor-collections
wso2bam
jack
ivalueconverter
gpu-programming
profiles
san
delphi-xe4
background-thread
ntlmv2
semantic-merge
onconfigurationchanged
pageheap
liveconnect
representation
tablet-pc
solandra
resharper-5.1
activestate
tabbarcontroller
asdoc
zend-test
browser-based
projectpier
data-retrieval
inversion
ntruencrypt
version-control-migration
suggestbox
remote-working
service-factory

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile