mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
you can set host in httpc header
This commit is contained in:
@@ -14,10 +14,15 @@ local function request(fd, method, host, url, recvheader, header, content)
|
|||||||
for k,v in pairs(header) do
|
for k,v in pairs(header) do
|
||||||
header_content = string.format("%s%s:%s\r\n", header_content, k, v)
|
header_content = string.format("%s%s:%s\r\n", header_content, k, v)
|
||||||
end
|
end
|
||||||
|
if header.host then
|
||||||
|
host = ""
|
||||||
|
end
|
||||||
|
else
|
||||||
|
host = string.format("host:%s\r\n",host)
|
||||||
end
|
end
|
||||||
|
|
||||||
if content then
|
if content then
|
||||||
local data = string.format("%s %s HTTP/1.1\r\nhost:%s\r\ncontent-length:%d\r\n%s\r\n%s", method, url, host, #content, header_content, content)
|
local data = string.format("%s %s HTTP/1.1\r\n%scontent-length:%d\r\n%s\r\n%s", method, url, host, #content, header_content, content)
|
||||||
write(data)
|
write(data)
|
||||||
else
|
else
|
||||||
local request_header = string.format("%s %s HTTP/1.1\r\nhost:%s\r\ncontent-length:0\r\n%s\r\n", method, url, host, header_content)
|
local request_header = string.format("%s %s HTTP/1.1\r\nhost:%s\r\ncontent-length:0\r\n%s\r\n", method, url, host, header_content)
|
||||||
|
|||||||
@@ -1,16 +1,24 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
local httpc = require "http.httpc"
|
local httpc = require "http.httpc"
|
||||||
|
local dns = require "dns"
|
||||||
|
|
||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
print("GET baidu.com")
|
print("GET baidu.com")
|
||||||
local header = {}
|
local respheader = {}
|
||||||
local status, body = httpc.get("baidu.com", "/", header)
|
local status, body = httpc.get("baidu.com", "/", respheader)
|
||||||
print("[header] =====>")
|
print("[header] =====>")
|
||||||
for k,v in pairs(header) do
|
for k,v in pairs(respheader) do
|
||||||
print(k,v)
|
print(k,v)
|
||||||
end
|
end
|
||||||
print("[body] =====>", status)
|
print("[body] =====>", status)
|
||||||
print(body)
|
print(body)
|
||||||
|
|
||||||
|
local respheader = {}
|
||||||
|
dns.server()
|
||||||
|
local ip = dns.resolve "baidu.com"
|
||||||
|
print(string.format("GET %s (baidu.com)", ip))
|
||||||
|
local status, body = httpc.get("baidu.com", "/", respheader, { host = "baidu.com" })
|
||||||
|
print(status)
|
||||||
|
|
||||||
skynet.exit()
|
skynet.exit()
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user