How does the php server accept json data sent by the android client?

Source: Internet
Author: User
Tags php server
What should I do if I want to implement communication between the php server and the android client and both parties transmit json data? {Code...} the android client can receive the sent json data, but the server does not seem to be able to receive it. The android client can receive the data sent by the server .. You guys... What should I do if I want to implement communication between the php server and the android client and the two parties transmit json data?

$reciver=file_get_contents('php://input');  5 //echo $reciver;  6   7   8 if(!empty($reciver))  9 { 10   $reciver=json_decode($reciver); 11  12   $code='200'; 13   $message='I have receiver it'; 14   $data='received'; 15 } 16 else 17 { 18   $code='400'; 19   $message='reciver bad'; 20   $data='not received '; 21 } 22  23  24  25 Response::responseResult 26 ($code,$message,$data);

The android client can receive the sent json data, but the server does not seem to be able to receive it. The android client can receive the data sent by the server ..

Thank you for your advice ..

Reply content:

What should I do if I want to implement communication between the php server and the android client and both parties transmit json data?

$reciver=file_get_contents('php://input');  5 //echo $reciver;  6   7   8 if(!empty($reciver))  9 { 10   $reciver=json_decode($reciver); 11  12   $code='200'; 13   $message='I have receiver it'; 14   $data='received'; 15 } 16 else 17 { 18   $code='400'; 19   $message='reciver bad'; 20   $data='not received '; 21 } 22  23  24  25 Response::responseResult 26 ($code,$message,$data);

The android client can receive the sent json data, but the server does not seem to be able to receive it. The android client can receive the data sent by the server ..

Thank you for your advice ..

Postman simulates sending data, and then outputs it to see the structure. Is it not easy to process the structure?

Capture the package and check whether the data has been transmitted.

View the data format and log

The server log prints the request to see the format of data sent by the client and then processes it.

It is best for the server client to check whether there is a problem with server reception and client sending. On the server side, you can use the postman plug-in the chorme browser to simulate sending requests to check whether your backend program is faulty. The client checks whether the request protocol address, parameters, and request method comply with the server-side protocol design. This problem is easy to find out.

Does your server jump? If no jump is made, your code will surely be available.

Check the request header of your client and use $ _ POST.

Android does not send the original post data packet and you cannot obtain it.

If this method is used, the Android client cannot submit a request using a form. Only JSON strings can be POST as request bodies.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.