से पोस्ट डेटा पास कर रहा है मैंने अपना पूरा दिन इस समस्या को समझने की कोशिश की है। यहां इस मुद्दे को पोस्ट करना मेरी आखिरी उम्मीद है। मुझे आशा है कि कोई मेरी पहली नौकरी पर काम जारी रखने में मदद कर सकता है।कोडइग्निटर रेस्ट क्लाइंट से रेस्टसेवर एपीआई
तो, पोस्ट सीधे ठीक से काम करता है जब सीधे मेरे विचारों से डेटा को रेस्टसेवर तक सीधे पास करता है। हालांकि, RESTServer API RestClient से भेजे गए POSTs डेटा को ढूँढने में सक्षम नहीं है।
RestClient API:
$ver = 'v1';
$config = array('server' => base_url()."v1",
'api_key' => 'xxxxxx',
'api_name' => 'X-API-KEY',
'http_user' => 'admin',
'http_pass' => 'xxxxx',
'http_auth' => 'basic',
);
$this->rest->initialize($config);
$this->rest->format('application/json');
$param = array(
'id' => $this->input->post('id'), // works fine here
'name' => $this->input->post('name')
);
$user = $this->rest->post('employer/postNewProject', $param, 'json');
//if (isset($user->errors)) show_404('admin');
$this->rest->debug();
RestServer एपीआई
class Employer extends REST_Controller
{
public function __construct()
{
parent::__construct();
$this->lang->load("application");
$this->load->library("users/auth");
Datamapper::add_model_path(array(APPPATH."modules"));
}
public function postNewProject_post()
{
// I tired $this->post() and $this->input->post() but both not finding the data
$message = array("id" => $this->post("id"), "name" => $this->input->post("name"));
$this->response($message, 200); // 200 being the HTTP response code
}
}
परिणाम::
Response when using $this->post('id');
{"id":false}
Response when using $this->post();
{"id":[]}
नोट:
यहाँ के टुकड़े कर रहे हैं मैं हार्डकोडेड डेटा के साथ पोस्ट अनुरोध बदल दिया है, और अभी भी RestServer मेरे RestClient से डेटा प्राप्त करने में सक्षम नहीं है।
यदि आपको मुझे कुछ और प्रदान करने की आवश्यकता है, तो कृपया पूछें।
अग्रिम धन्यवाद।
केवल $ JS- 'rest-> format (' json ') जैसे सेट जेएस के साथ सेट प्रारूप के साथ प्रयास करें; ' – jagad89