'ltn12'에 해당되는 글 2건

  1. 2014.01.08 [LUA] http authorization (GET/POST)
  2. 2014.01.08 [LUA] HTTP 요청 결과 (Response body) 얻기 1
프로그래밍/LUA2014. 1. 8. 10:36
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.


lua에서 HTTP로 인증을 받는 방법입니다.


local http = require("socket.http");

local ltn12 = require("ltn12");


local respbody = {};


-- url

local request_url = "http://...testurl/test.lua";


-- user id / password

local userinfo = "user_name:password";


-- post data

local postData = "REQUEST_BODY";



if postData == nil then

http.request{

url = request_url,

sink = ltn12.sink.table(respbody),

headers = { authorization = "Basic " .. (mime.b64(userinfo)) }

}

else

http.request{

url = request_url,

method = "POST",

sink = ltn12.sink.table(respbody),

source = ltn12.source.string(postData),

headers = {

authorization = "Basic " .. (mime.b64(userinfo));

["Content-Length"] = string.len(postData);

}

}

end


local respString = table.concat(respbody);


print ("## Response:");

print (respString);




※ 퍼가실땐 출처를 밝혀주세요. (http://shkam.tistory.com/)


Posted by 고독한 프로그래머
프로그래밍/LUA2014. 1. 8. 10:20
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.



LUA 에서 다른 사이트에 Request를 보낸 후 Response의 내용을 변수에 저장하는 방법입니다. 


빨간색 부분의 URL을 수정해서 사용하시면 됩니다.


local http = require("socket.http");

local ltn12 = require("ltn12");


local respbody = {};


http.request{

url = "http://tvpot.cdn.videofarm.daum.net/crossdomain.xml",

sink = ltn12.sink.table(respbody),

}


local respString = table.concat(respbody);


print ("## Response:");

print (respString);


## Response:
<?xml version="1.0" encoding="UTF-8"?><cross-domain-policy><allow-access-from domain="*"/></cross-domain-policy>
>Exit code: 0




※ 퍼가실땐 출처를 밝혀주세요. (http://shkam.tistory.com/)


Posted by 고독한 프로그래머