2015-02-02 1 views
1

codeigniter를 사용 중이고 openfire에 추가 요청을 보내려고하지만 실제로해야 할 일을 정말로 이해하지 못합니다. 저는 초보자입니다.이 가이드 User Service을 읽었으며 새 사용자를 곱슬 곱슬 한 Curl lib으로 추가하려고 시도했지만 막혔습니다. 내가 브라우저에서 요청을 할 경우 추가가 를 작동하기 때문에의 Openfire이 제대로이 내 코드openfire에 사용자 서비스 요청 보내기

$this->load->library('curl'); 
    $username='usertest'; 
    $password='password'; 
    $header='Authorization'; 
    $content='mykey'; 
    $this->curl->create('http://myserver.net', 9090); 
    $this->curl->http_header($header, $content); 
    $this->curl->http_header('Content-Type', 'application/xml'); 
    $this->curl->post(array('username'=>$username,'password'=>$password)); 
    $this->curl->execute(); 

입니다 그러나 사용자가

내 나쁜 영어 죄송

을 추가되지 않습니다

다음
+1

다음 두 번째 부분을 살펴보십시오. http://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter-2--net-8814 – AdrienXL

+0

도움을 주셔서 감사합니다. 이 가이드에는 더 이상 오류가 없지만 사용자가 추가되지 않았으므로 Autentication 또는 게시 매개 변수에 문제가 있다고 생각합니다. –

답변

1

하나입니다 구성 사용자 서비스 클라이언트 구현 (Curl을 기반으로하지만 코드 서명자를 기반으로하지 않음) :

$url = "http://localhost:9090/plugins/userService/users"; 
    $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
    <user> 
    <username>'.$user['username'].'</username> 
    <password>'.$user['password'].'</password> 
    <name>'.$user['name'].'</name> 
    <email>'.$user['email'].'</email> 
    </user>'; 



    //open connection 
    $ch = curl_init(); 


    //set the url, number of POST vars, POST data 
    curl_setopt($ch,CURLOPT_URL, $url); 
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); 
    curl_setopt($ch,CURLOPT_HEADER,true); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization: secret', 
    'Content-Type: application/xml' 
)); 
    curl_setopt($ch, CURLOPT_POST,   1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,  $xml); 
    #curl_setopt($ch,CURLOPT_POSTFIELDSPOST, count($fields)); 
    #curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); 


    //execute post 
    $result = curl_exec($ch); 
    $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    ob_start(); // outer buffer 
    #echo "Code: $http_status | Username: {$user['name']}\n"; 
    ob_end_flush(); 
    //close connection 
    curl_close($ch); 

    if ($http_status == 201) { 
    return true; 
    } 
    else return false; 

컨텐츠 유형 및 인증을 설정해야합니다 헤더의 배열로 orization. 그리고 XML 내용이 잘못되었습니다. 배열에있는 사용자 이름/암호 만이 아닙니다.