Action() { int nHttpRetCode; // 默认最大长度为256,get请求需注意缓存问题,需要根据content-length进行修改 web_set_max_html_param_len("262144"); //自定义截取字符串,根据左右字符串获取数据,设置查找范围为消息体、左右查找边界为空则可以获取整个响应体的内容 web_reg_save_param("ResponseBody", "LB=", "RB=", "Search=Body", LAST); // REQUEST为内置变量,保存请求的头信息,需在发送URL请求前注册使用,将请求头信息存入字符串RequestHeader中 web_save_header(REQUEST, "RequestHeader"); // 将RESPONSE保存响应的头信息在字符串ResponseHeader中 web_save_header(RESPONSE, "ResponseHeader"); web_custom_request("cnblog", "URL=http://cnblogs.com/guanfuchang", "Method=GET", "Resource=0", "Referer=", "Mode=HTTP", "EncType=text/html;charset=UTF-8", "Body=", LAST); //字符转码 lr_convert_string_encoding(lr_eval_string("{RequestHeader}"),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE,"RequestHeaderUTF8"); lr_convert_string_encoding(lr_eval_string("{ResponseHeader}"),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE,"ResponseHeaderUTF8"); lr_convert_string_encoding(lr_eval_string("{ResponseBody}"),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE,"ResponseBodyUTF8"); //输出信息 lr_eval_string()将参数值转换成字符串 lr_output_message("# 请求头信息: %s", lr_eval_string("{RequestHeaderUTF8}")); lr_output_message("# 响应头信息: %s", lr_eval_string("{ResponseHeaderUTF8}")); lr_output_message("# 响应内容体: %s", lr_eval_string("{ResponseBodyUTF8}")); //获取服务器http响应码,HTTP_INFO_RETURN_CODE变量在请求后使用 nHttpRetCode = web_get_int_property(HTTP_INFO_RETURN_CODE); if(nHttpRetCode == 200){ lr_output_message("Success!"); }else{ lr_output_message("Failed! "); } return 0; }
转载:https://www.cnblogs.com/guanfuchang/p/6203994.html
Action() { int nHttpRetCode; // 默认最大长度为256,get请求需注意缓存问题,需要根据content-length进行修改 web_set_max_html_param_len( "262144" ); //自定义截取字符串,根据左右字符串获取数据,设置查找范围为消息体、左右查找边界为空则可以获取整个响应体的内容 web_reg_save_param( "ResponseBody" , "LB=" , "RB=" , "Search=Body" , LAST); // REQUEST为内置变量,保存请求的头信息,需在发送URL请求前注册使用,将请求头信息存入字符串RequestHeader中 web_save_header(REQUEST, "RequestHeader" ); // 将RESPONSE保存响应的头信息在字符串ResponseHeader中 web_save_header(RESPONSE, "ResponseHeader" ); web_custom_request( "cnblog" , "URL=http://cnblogs.com/guanfuchang" , "Method=GET" , "Resource=0" , "Referer=" , "Mode=HTTP" , "EncType=text/html;charset=UTF-8" , "Body=" , LAST); //字符转码 lr_convert_string_encoding(lr_eval_string( "{RequestHeader}" ),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE, "RequestHeaderUTF8" ); lr_convert_string_encoding(lr_eval_string( "{ResponseHeader}" ),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE, "ResponseHeaderUTF8" ); lr_convert_string_encoding(lr_eval_string( "{ResponseBody}" ),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE, "ResponseBodyUTF8" ); //输出信息 lr_eval_string()将参数值转换成字符串 lr_output_message( "# 请求头信息:
%s" , lr_eval_string( "{RequestHeaderUTF8}" )); lr_output_message( "# 响应头信息:
%s" , lr_eval_string( "{ResponseHeaderUTF8}" )); lr_output_message( "# 响应内容体:
%s" , lr_eval_string( "{ResponseBodyUTF8}" )); //获取服务器http响应码,HTTP_INFO_RETURN_CODE变量在请求后使用 nHttpRetCode = web_get_int_property(HTTP_INFO_RETURN_CODE); if (nHttpRetCode == 200){ lr_output_message( "Success!" ); } else { lr_output_message( "Failed! " ); } return 0; } |