btray77 Posted October 21, 2009 Share Posted October 21, 2009 Ruby Code: { "itemFilter" => { "keywords" => "milk" }} my_input = { "itemFilter" => { "keywords" => "milk" }}.to_json # Turn hash input into JSON, store it in variable called "my_input" @http = Net::HTTP.new("website.com") # Open connection to website.com response_code, data = @http.post("/requests", "findItems=#{my_input}") # Post the request to our API, with the "findItems" name and our JSON from above as the value response_code, data = @http.post("/requests", "findItems=#{input}", {'X-CUSTOM-HEADER' => 'MYCUSTOMCODE'}) my_hash = Crack::JSON.parse(data) my_milk = my_hash["findItems"]["item"].first Here's what I have so far, which might be totally wrong.. Any help would be appreciated. <?PHP $requestBody =json_encode(array("itemFilter" => array( "keywords" => "milk" ))); $headers = array ( //set the keys 'X-CUSTOM-HEADER: ' .'MYCUSTOMCODE', ); //initialise a CURL session $connection = curl_init(); //set the server we are using (could be Sandbox or Production server) curl_setopt($connection, CURLOPT_URL, 'http://www.website.com/request/findItems='); //stop CURL from verifying the peer's certificate curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0); //set the headers using the array of headers curl_setopt($connection, CURLOPT_HTTPHEADER, $headers); //set method as POST curl_setopt($connection, CURLOPT_POST, 1); //set the XML body of the request curl_setopt($connection, CURLOPT_POSTFIELDS, $requestBody); //set it to return the transfer as a string from curl_exec curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1); //Send the Request $response = curl_exec($connection); //close the connection curl_close($connection); print_r($response); Thanks -Brad Link to comment https://forums.phpfreaks.com/topic/178540-convert-ruby-code-to-php-help-please/ Share on other sites More sharing options...
btray77 Posted October 22, 2009 Author Share Posted October 22, 2009 found the problem: http://www.website.com/request/findItems= should be http://www.website.com/request?findItems= Thanks if you were working on helping me on this. -Brad Link to comment https://forums.phpfreaks.com/topic/178540-convert-ruby-code-to-php-help-please/#findComment-941781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.