I don’t have time to properly update this article right now, but I want to mention this in case you run into the problem shown in the Comments below. Note: I should have used the PHP encode and decode functions in this example, as I describe in my PHP Base64 encode and decode functions article. I don’t have time to document these examples today, but if you need some PHP curl examples, including how to set curl options with curl_setopt, I hope these examples have been helpful. strlen($data_string))Ĭurl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5) Viewed 750 times Part of PHP Collective 0 Im messing with the teamsnap API which uses Collection + JSON which seems to be making it a bit more difficult to extract specific data (at least for me). iniset ('displayerrors', 'On') errorreporting (EALL) Also try to print the raw response before jsondecoding it, this is because if the response you are getting is not valid json nothing would be printed out. use these at the top of the file, just after the php tags. Ask Question Asked 6 years, 5 months ago. Try displaying errors just in case the errors/warnings are suppressed. $ch = curl_init(' curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST") Ĭurl_setopt($ch, CURLOPT_POSTFIELDS, $data_string) Ĭurl_setopt($ch, CURLOPT_RETURNTRANSFER, true) Ĭurl_setopt($ch, CURLOPT_HTTPHEADER, array( PHP Curl, Collection + JSON Response for specific field. "$id", "symbol" => "$symbol", "companyName" => "$companyName") The Sencha client gives this script the data in a POST format, and this script converts that data to JSON, passes it to the URL shown, and returns whatever information that service returns directly to the Sencha client: The way this script works is that it sits in the middle of (a) a Sencha ExtJS client and (b) another web service at the URL shown. This next example makes an HTTP POST request. Convert a Curl Response String in JSON Array with PHP. superphonic: No, I do not have control of the external server. This first example makes an HTTP GET request and prints the data that is returned by the URL that it hits: Maybe ask the people you are sending the request to if there is a parameter to pass to make it a json response Ryan. The first example makes a GET request, and the second example makes a POST request, and passes JSON data to the web service it accesses. Here are two PHP scripts I just wrote that use curl and curl_setopt.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |