获取天气的url地址:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?op=getWeatherbyCityName
第一种方法:
1.在lr12里新建一个Web Services协议的项目
2.点击manage services
点击import,选择URL填写url地址信息
lr_start_transaction("获取天气预报");
web_service_call(
"StepName=getWeatherbyCityName_101",//步骤名称
"SOAPMethod=WeatherWebService|WeatherWebServiceSoap|getWeatherbyCityName",//调用的一些服务的名称|soap|请求的方法获取哪个接口(城市天气预报)
"ResponseParam=response",//返回的参数信息
"Service=WeatherWebService",//webservice的服务
"ExpectedResponse=SoapResult",//请求的返回信息
"Snapshot=t1555506334.inf",//快照
BEGIN_ARGUMENTS,//开始输入参数
"theCityName={city_name}",//请求输入的数据,城市={city_name}
END_ARGUMENTS,//结束参数的输入
BEGIN_RESULT,//返回值的开始
"getWeatherbyCityNameResult/*[1]=Param_string",//返回的参数保存在Param_string里面,[1]是数组的下标
END_RESULT,//返回值的结束
LAST);
if(strcmp(lr_eval_string("{Param_string}"),lr_eval_string("{city_name}"))==0)
{
lr_end_transaction("获取天气预报",LR_PASS);
}
else
{
lr_end_transaction("获取天气预报",LR_FAIL);
}
第二种方法
1.先把请求数据存放到记事本里,改后缀为xml
2.lr里
导入刚刚的xml文件
3.
lr_convert_string_encoding("厦门",NULL,"utf-8","cityname");//将中文的utf-8转换成lr的编码方式
//lr_convert_string_encoding(lr_eval_string
lr_save_string(lr_eval_string("{cityname}"),"city_name");//把cityname保存给city_name
soap_request("StepName=SOAP Request", //步骤的名称
"URL=http://www.webxml.com.cn/WebServices/WeatherWebService.asmx", //请求的url
"SOAPEnvelope="//发送到服务器的xml包
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
"<soap:Body>"
"<getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\">"
"<theCityName>{city_name}</theCityName>"
"</getWeatherbyCityName>"
"</soap:Body>"
"</soap:Envelope>",
"SOAPAction=http://WebXml.com.cn/getWeatherbyCityName",
"ResponseParam=response", //存储服务器响应的输出参数的名称
"Snapshot=t1555509167.inf",
LAST);
lr_convert_string_encoding(lr_eval_string("{response}"),"utf-8",NULL,"msg");
//通过这个函数来获取参数值
lr_xml_get_values("XML={response}",
"Query=/Envelope/Body/getWeatherbyCityNameResponse/getWeatherbyCityNameResult/string[2]",//对输入字符串xml的查找或快速查找,指定元素或属性
"ValueParam=city_code",//存储查询结果的输出参数的名称
LAST);
lr_output_message("返回的城市名称:%s",lr_eval_string("{city_code}"));
第三种方法
忘记了可以用检查点来做if判断
复习了检查点,后续要慢慢看视频补充笔记到博客
Action()
{
lr_convert_string_encoding(lr_eval_string("{city_name_value}"),NULL,"utf-8","cityname");
lr_save_string(lr_eval_string("{cityname}"),"city_name");//把cityname保存给city_name
lr_start_transaction("获取天气预报");
//根据城市名称做检查点
web_reg_find("Search=Body",
"SaveCount=city_name_count",//统计检查点的次数
"Text={city_name}",//要检查的参数
LAST);
web_custom_request("web_custom_request",
"URL=http://www.webxml.com.cn/WebServices/WeatherWebService.asmx",
"Method=POST",
"TargetFrame=",//fram名称
"Resource=0",
"Referer=",
"Mode=HTTP",
"EncType=text/xml; charset=utf-8",
"BodyBinary=<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
"<soap:Body>"
"<getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\">"
"<theCityName>{city_name}</theCityName>"
" </getWeatherbyCityName>"
"</soap:Body>"
"</soap:Envelope>",
LAST);
//atoi:指定的字符转换成整型
//lr_eval_string:获取当前参数的值
if(atoi(lr_eval_string("{city_name_count}"))>=1)
{
lr_end_transaction("获取天气预报",LR_PASS);
}
else
{
lr_end_transaction("获取天气预报",LR_FAIL);
}
return 0;
}