lua-resty-http
lua-resty-http copied to clipboard
read status line failed read status line failed timeout
os:mac docker image build by
FROM alpine
MAINTAINER edwin_uestc <[email protected]>
ENV LUA_SUFFIX=jit-2.1.0-beta1 \
LUAJIT_VERSION=2.1 \
NGINX_PREFIX=/opt/openresty/nginx \
OPENRESTY_PREFIX=/opt/openresty \
OPENRESTY_SRC_SHA1=1a2029e1c854b6ac788b4d734dd6b5c53a3987ff \
OPENRESTY_VERSION=1.9.7.3 \
VAR_PREFIX=/var/nginx
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/' /etc/apk/repositories
RUN set -ex \
&& apk --no-cache add --virtual .build-dependencies \
curl \
make \
musl-dev \
gcc \
ncurses-dev \
openssl-dev \
pcre-dev \
perl \
readline-dev \
zlib-dev \
\
&& curl -fsSL http://openresty.org/download/openresty-${OPENRESTY_VERSION}.tar.gz -o /tmp/openresty.tar.gz \
\
&& cd /tmp \
&& echo "${OPENRESTY_SRC_SHA1} *openresty.tar.gz" | sha1sum -c - \
&& tar -xzf openresty.tar.gz \
\
&& cd openresty-* \
&& readonly NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
&& ./configure \
--prefix=${OPENRESTY_PREFIX} \
--http-client-body-temp-path=${VAR_PREFIX}/client_body_temp \
--http-proxy-temp-path=${VAR_PREFIX}/proxy_temp \
--http-log-path=${VAR_PREFIX}/access.log \
--error-log-path=${VAR_PREFIX}/error.log \
--pid-path=${VAR_PREFIX}/nginx.pid \
--lock-path=${VAR_PREFIX}/nginx.lock \
--with-luajit \
--with-pcre-jit \
--with-ipv6 \
--with-http_ssl_module \
--without-http_ssi_module \
--with-http_realip_module \
--without-http_scgi_module \
--without-http_uwsgi_module \
--without-http_userid_module \
-j${NPROC} \
&& make -j${NPROC} \
&& make install \
\
&& rm -rf /tmp/openresty-* \
&& apk del .build-dependencies
RUN ln -sf ${NGINX_PREFIX}/sbin/nginx /usr/local/bin/nginx \
&& ln -sf ${NGINX_PREFIX}/sbin/nginx /usr/local/bin/openresty \
&& ln -sf ${OPENRESTY_PREFIX}/bin/resty /usr/local/bin/resty \
&& ln -sf ${OPENRESTY_PREFIX}/luajit/bin/luajit-* ${OPENRESTY_PREFIX}/luajit/bin/lua \
&& ln -sf ${OPENRESTY_PREFIX}/luajit/bin/luajit-* /usr/local/bin/lua
RUN apk --no-cache add \
libgcc \
libpcrecpp \
libpcre16 \
libpcre32 \
libssl1.0 \
libstdc++ \
openssl \
pcre
WORKDIR $NGINX_PREFIX
CMD ["nginx", "-g", "daemon off; error_log /dev/stderr info;"]
i am trying to build post request using following code
local http = require "resty.http"
local hc = http:new()
local ok, code, headers, status, body = hc:request {
url = "http://wi.hit.edu.cn/cemr/",
-- proxy = "202.118.253.110:80",
timeout = 3000,
method = "POST", -- POST or GET
headers = { ["Upgrade-Insecure-Requests"]="1",["referer"]="http://wi.hit.edu.cn/cemr/",["cache-control"]="max-age=0",["connection"]="keep-alive",["user-agent"]="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:48.0) Gecko/20100101 Firefox/48.0",["host"]="wi.hit.edu.cn",["Content-Length"]="705",["Content-Type"] = "application/x-www-form-urlencoded" },
-- body = "source=1. 患者既往有高血压病史,最高达180/100mmHg,口服北京降压灵、利血平治疗,有脑梗死病史,遗留语笨及左侧肢体无力.2. 门诊行头CT检查,显示左侧侧脑室体旁低密度病灶,以脑梗死收入我科."
-- -- headers = { UserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11"}
}
ngx.say(ok)
ngx.say(code)
ngx.say(status)
ngx.say(body)
outcome i am looking for is to realize post request in the following page http://wi.hit.edu.cn/cemr/, the full request info i get from firefox debug tools is
Host: wi.hit.edu.cn
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://wi.hit.edu.cn/cemr/
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
form-data
source:"1.+患者既往有高血压病史,最高达180/100mmHg,口服"北京降压灵、利血平"治疗,有脑梗死病史,遗留语笨及左侧肢体无力.
2.+门诊行头CT检查,显示左侧侧脑室体旁低密度病灶,以"脑梗死"收入我科."
full error is like this
2016/09/17 05:53:47 [error] 7#0: *10 lua tcp socket read timed out, client: 172.17.0.1, server: , request: "GET /cemr HTTP/1.1", host: "localhost:8080"
but curl works curl -d "source=患者既往有高血压病史,最高达180/100mmHg,口服北京降压灵、 利血平治疗,有脑梗死病史,遗留语笨及左侧肢体无力." http://wi.hit.edu.cn/cemr/ > result.html