2013-11-28 4 views
0

단일 세션에서 여러 게시물 요청을 보내기위한 perl 스크립트 작성. 따라서 첫 번째 요청을 보낼 때마다 세션 ID가 반환됩니다. 동일한 세션 ID로 다음 요청을 수행해야합니다. HTTP 헤더에 해당 세션을 포함시키는 방법. http : 쿠키 헤더를 사용하고 싶지 않습니다. http 헤더에 직접 세션 ID를 전달할 수 있습니까? ? ( 작동하지 않음)http post 요청에 대한 wirte perl 스크립트 (이전 resd 포함)

샘플 코드는

$server_endpoint = "https://ip/nitro/v1/discovery/device_registration"; 
$post_data = '{"device_registration":{"device_ipaddress":"ip","device_family":"CB"}}'; 
$req = HTTP::Request->new(POST => $server_endpoint); 
$req->header('content-type' => 'application/json'); 
$req->header('cookie' => 'sessionid=$sessionid;'); # can I avoid setting a cookie? 
$req->content($post_data); 

답변

1

이 서비스가 세션 id를받을 것으로 예상되는 방식에 따라 달라집니다. API 설명서에서 해당 내용을 찾아야합니다.

서비스가 POST 데이터의 일환으로 세션 id를 기대하는 경우에, 당신은 쉽게 업데이트의 해시에 POST 데이터를 유지할 수 있으며,이 요청 발행 할 때입니다 경우에만 직렬화 :

use JSON; 

$server_endpoint = "https://ip/nitro/v1/discovery/device_registration"; 
$post_data = { 
    device_registration => { 
     device_ipaddress => 'ip', 
     device_family => 'CB', 
    } 
}; 

$req = HTTP::Request->new(POST => $server_endpoint); 
$req->header('Content-Type' => 'application/json'); 

$post_data->{sessionid} = $sessionid; 
$req->content(JSON::to_json($post_data)); 

하지만 이것이 특정 경우에 작동하는지 여부는 서비스가 세션 ID 전달을 기대하는 방식에 따라 다릅니다.

+0

그래서 UI에서 가져 오는 방법을보고 싶다면 어떻게 확인하나요? – Kranthi

+0

내가 말했듯이 API 설명서를 확인해야합니다. 이것은 당신이 쓰고있는 서비스입니까? http://support.citrix.com/servlet/KbServlet/download/30602-102-681756/NS-Nitro-Gettingstarted-guide.pdf이 문서에서는 인증 토큰을 실제로 HTTP 쿠키로 전달해야한다고 제안합니다. –

관련 문제