Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have created that needs to take post values and return a JSON encoded array.
That all worked fine until I was told I would need to post the form data with a content-type of application/json.
Since then I cannot return any values from the web service and it is definitely something to do with how I am filtering their post values
Basically I know that it is due to the $_POST values not being set but I can't find what I need to put instead of the $_POST. I tried json_decode($_POST), file_get_contents("php://input") and a number of other ways but I was shooting in the dark a bit.
Any help would be greatly appreciated.
You have empty $_POST. If your web-server wants see data in json-format you need to read the raw input and then parse it with JSON decode You need something like that
$input = file_get_contents('php://input');
$result = json_decode($input);
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 days ago.
Improve this question
Post request empty data receiving through postman Api With codeigniter 3 it turns into get request.
Post Request Automatic Converted Into Get Request.
$_POST or $this->input->post() is receiving as an empty array !
I tried it from php curL or many ways but always get as an empty array !
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am using a library to make API call to the Instagram API. And I am getting a response like this:
POST: https://i.instagram.com/api/v1/feed/timeline/
DATA: is_prefetch=0&feed_view_info=&seen_posts=&phone_id=4c14088a-94b7-49c3-bec3-12caad443c50&reason=pull_to_refresh&battery_level=100
← 200 15.19kB
RESPONSE: {"response": "Random Json Response"}
I want the value of the response key from here.
What is the strategy to parse it? Or this is a special kind of software architecture style like SOAP or REST?
What you're probably looking for is the apache_request_headers() function.
You would use it like so:
$response = apache_request_headers();
print_r($response);
This will generate an array where you will be able to retrieve the information that you need.
The RESPONSE: data is in the JSON format. So you will need to convert it to an array like so:
$responseData = json_decode($responseData, true);
print_r($responseData);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I was trying to build a script that could get me definitions of words from the wikipedia API in php.
I tried several obtaining the definitions in an array and displaying the first definition but it didn't work. Can anyone please help me out. Any help is appreciated
Which parameters did you use in your request?
You can take this as an example:
https://en.wikipedia.org/w/api.php?action=opensearch&search=PHP&limit=1&format=json
You said there that you want only the first definition, so you can put limit=1. The response is in json.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have a field in one of my database tables, a sample of this field looks like so ; ["1","4","7"]. Those are keys to a reference in another table. What i want to do is fetch the field and ideally loop through the values and get the data from the referenced table. As you will notice, ["1","4","7"] is PHP declaration for an array but for the life of me, I am unable to parse it as an array. How do i parse it as an array? What am I missing?
You should be able to decode and convert it into an array with PHP's json_decode function.
Example:
<?php
echo '<pre>';
print_r(json_decode('["1","4","7"]'));
echo '</pre>';
?>
If I understood your problem is that your database column store a string PHP array representation.
So you should use the function json_decode
By the way it's a strange way to store relation in a database
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Am fetching data from mysqlite to a string array which i want to submit to PHP then update a mysql table.
Any easy way out, because doesn't seem to work?
I suggest using the network monitor tool to see that the Codename One code is sending out the right data as explained in the IO section of the developer guide.
I notice your PHP code tries to decode JSON into an array whereas your Java code adds a POST array both of which have nothing in common. I don't really know PHP's equivalent for handling an array so I can't help you there. On the Codename One side you can just write the array as JSON by converting it to a JSON String.