// 增加NAT项过程启动...
procedure TForm1.Button3Click(Sender: TObject);
begin
controled:=false;
controltype:=1;
controlresponse:='';
controlsocket.host:=routerip;
controlsocket.Port:=routerport;
controlsocket.Active:=true;
memo1.lines.add('向'+routerip+':'+inttostr(routerport)+'设备发起增加NAT项的连接...');
memo1.lines.add('');
end;
procedure TForm1.ControlSocketConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
memo1.lines.add('与'+routerip+':'+inttostr(routerport)+'设备成功连接');
memo1.lines.add('');
end;
procedure TForm1.ControlSocketWrite(Sender: TObject;
Socket: TCustomWinSocket);
var
request,body,curl: string;
j: integer;
begin
//
// 假如已经提交,则不再提交...
if controled then
exit;
curl:=controlurl;
if uppercase(copy(curl,1,7))='HTTP://' then
delete(curl,1,7);
j:=pos('/',curl);
delete(curl,1,j-1);
//
// 得到请求串...
case controltype of
//
// 增加NAT项时...
1: begin
body:='<?xml version="1.0"?>'#13#10
+'<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"'#13#10
+'s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'#13#10
+'<s:Body>'#13#10
+'<u:AddPortMapping xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">'#13#10
+'<NewRemoteHost></NewRemoteHost>'#13#10
+'<NewExternalPort>888</NewExternalPort>'#13#10
+'<NewProtocol>tcp</NewProtocol>'#13#10
+'<NewInternalPort>888</NewInternalPort>'#13#10
+'<NewInternalClient>192.168.0.5</NewInternalClient>'#13#10
+'<NewEnabled>1</NewEnabled>'#13#10
+'<NewPortMappingDeion>测试</NewPortMappingDeion>'#13#10
+'<NewLeaseDuration>1600</NewLeaseDuration>'#13#10
+'</u:AddPortMapping>'#13#10
+'</s:Body>'#13#10
+'</s:Envelope>'#13#10;
request:='POS