[转帖] web_custom_request应用示…

我们通过树型模式查看一下在submit form的时候实际向服务器发出的请求的内容:
[转帖] <wbr>web_custom_request应用示例<2>

从请求内容中可以看到,我们通过POST方法发出了请求,请求发送的目的URL是/MercuryWebTours/itinerary.pl,发送的内容是:
"1=on&flightID=384-798-JM&2=on&flightID=3026-1592-JM&3=on&flightID=1194-2326-JM&.cgifields=1&.c"
"gifields=2&.cgifields=3&removeFlights.x=116&removeFlights.y=8"

从发送的内容中可以很明显的分析得出,1=on表示第一个checkbox是被选中的,flightID=384-798-JM表示的是第一条记录所对应的flightID。因此,如果我们需要自己组成这个发送的request的话,必须首先通过关联的方式获得前两条记录的flightID,然后再组成request的内容。

web_custom_request方法的原型是:
int web_custom_request (const char *RequestName, <List of Attributes>,[EXTRARES, <List of Resource Attributes>,] LAST );

其中List of Attributes的主要项目是Method,URL和BODY等。对这个例子来说,我们可以很容易构造出我们需要的request的BODY内容。
……
 strcpy(creq, "Body=1=on&flightID=");
 strcat(creq, lr_eval_string("{fID1}"));
 strcat(creq, "&2=on&flightID=");
 strcat(creq, lr_eval_string("{fID2}"));
 strcat(creq, "&.cgifields=1&.cgifields=2");
 strcat(creq, "&removeFlights.x=116&removeFlights.y=8");
……

其中{fID1}、{fID2}等都是通过关联获得的flightID的数据。

因此,我们可以根据图中的数据编写custom_request语句:

[转帖] <wbr>web_custom_request应用示例<2> web_custom_request( " itinerary.pl " ,
[转帖] <wbr>web_custom_request应用示例<2>
" Method=POST "
[转帖] <wbr>web_custom_request应用示例<2>    
" URL=http://localhost/MercuryWebTours/itinerary.pl " ,
[转帖] <wbr>web_custom_request应用示例<2>    
" RecContentType=text/xml " ,
[转帖] <wbr>web_custom_request应用示例<2>    creq,
[转帖] <wbr>web_custom_request应用示例<2>    
" Snapshot=t4.inf " ,
[转帖] <wbr>web_custom_request应用示例<2>    LAST);

较为完整的代码如下:
[转帖] <wbr>web_custom_request应用示例<2> Action()
[转帖] <wbr>web_custom_request应用示例<2>
{
[转帖] <wbr>web_custom_request应用示例<2>    
char creq[500];
[转帖] <wbr>web_custom_request应用示例<2>
[转帖] <wbr>web_custom_request应用示例<2>    web_reg_save_param(
"fID1""LB=INPUT TYPE=\"hidden\" NAME=\"flightID\" VALUE=\"""RB=\"""ORD=1"
[转帖] <wbr>web_custom_request应用示例<2>        
"SEARCH=BODY", LAST);
[转帖] <wbr>web_custom_request应用示例<2>    web_reg_save_param(
"fID2""LB=INPUT TYPE=\"hidden\" NAME=\"flightID\" VALUE=\"""RB=\"""ORD=2"
[转帖] <wbr>web_custom_request应用示例<2>        
"SEARCH=BODY", LAST);
[转帖] <wbr>web_custom_request应用示例<2>    web_url(
"welcome.pl",
[转帖] <wbr>web_custom_request应用示例<2>        
"URL=http://localhost/MercuryWebTours/welcome.pl?page=itinerary",
[转帖] <wbr>web_custom_request应用示例<2>        
"Resource=0",
[转帖] <wbr>web_custom_request应用示例<2>        
"RecContentType=text/html",
[转帖] <wbr>web_custom_request应用示例<2>        
"Referer=http://localhost/MercuryWebTours/nav.pl?page=menu&in=home",
[转帖] <wbr>web_custom_request应用示例<2>        
"Snapshot=t3.inf",
[转帖] <wbr>web_custom_request应用示例<2>        
"Mode=HTML",
[转帖] <wbr>web_custom_request应用示例<2>        EXTRARES,
[转帖] <wbr>web_custom_request应用示例<2>        
"URL=images/in_itinerary.gif""Referer=http://localhost/MercuryWebTours/nav.pl?page=menu&in=itinerary", ENDITEM,
[转帖] <wbr>web_custom_request应用示例<2>        
"URL=images/home.gif""Referer=http://localhost/MercuryWebTours/nav.pl?page=menu&in=itinerary", ENDITEM,
[转帖] <wbr>web_custom_request应用示例<2>        LAST);
[转帖] <wbr>web_custom_request应用示例<2>    lr_think_time(
2);
[转帖] <wbr>web_custom_request应用示例<2>
[转帖] <wbr>web_custom_request应用示例<2>    strcpy(creq, 
"Body=1=on&flightID=");
[转帖] <wbr>web_custom_request应用示例<2>    strcat(creq, lr_eval_string(
"{fID1}"));
[转帖] <wbr>web_custom_request应用示例<2>    strcat(creq, 
"&2=on&flightID=");
[转帖] <wbr>web_custom_request应用示例<2>    strcat(creq, lr_eval_string(
"{fID2}"));
[转帖] <wbr>web_custom_request应用示例<2>    strcat(creq, 
"&.cgifields=1&.cgifields=2");
[转帖] <wbr>web_custom_request应用示例<2>    strcat(creq, 
"&removeFlights.x=116&removeFlights.y=8");
[转帖] <wbr>web_custom_request应用示例<2>
[转帖] <wbr>web_custom_request应用示例<2>    lr_output_message(creq);
[转帖] <wbr>web_custom_request应用示例<2>
[转帖] <wbr>web_custom_request应用示例<2>    web_custom_request(
"itinerary.pl",
[转帖] <wbr>web_custom_request应用示例<2>
"Method=POST"
[转帖] <wbr>web_custom_request应用示例<2>        
"URL=http://localhost/MercuryWebTours/itinerary.pl",
[转帖] <wbr>web_custom_request应用示例<2>        
"RecContentType=text/xml",
[转帖] <wbr>web_custom_request应用示例<2>        creq,
[转帖] <wbr>web_custom_request应用示例<2>        
"Snapshot=t4.inf",
[转帖] <wbr>web_custom_request应用示例<2>        LAST);
[转帖] <wbr>web_custom_request应用示例<2>
[转帖] <wbr>web_custom_request应用示例<2>    
return 0;
[转帖] <wbr>web_custom_request应用示例<2>}

你可能感兴趣的:([转帖] web_custom_request应用示…)