#define BUFF_SIZE 40000
#define RD_BLOCK_SIZE 128
STREAM* pTcpStream = stream_create("/dev/tcp/192.168.178.41/905",0,0); // create tcp stream
char* pTcpCmd = "POST /loewe_tablet_0001 HTTP/1.1\r\nHost: 192.168.178.41:905\r\nUser-Agent: LoxLIVE [en]\r\nContent-Length: 409\r\nContent-Type: application/soap+xml; charset=utf-8\r\nSOAPACTION: RequestAccess\r\n\r\n<?xml version="1.0"?><env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ltv="urn:loewe.de:RemoteTV:Tablet"><env:Body ><ltv:RequestAccess><fcid>81</fcid><ClientId>?</ClientId><DeviceType>Loxone Miniserver</DeviceType><DeviceName>lxl0BB7</DeviceName><DeviceUUID>50:4F:94:10:0B:B7</DeviceUUID><RequesterName>Assist Media App</RequesterName></ltv:RequestAccess></env:Body></env:Envelope>";
stream_write(pTcpStream,pTcpCmd,strlen(pTcpCmd)); // write to output buffer
stream_flush(pTcpStream); // flush output buffer
char szBuffer[BUFF_SIZE];
char szTmpBuffer[RD_BLOCK_SIZE];
int nCnt;
int nBytesReceived = 0;
int i = 0;
// read stream
do
{
nCnt = stream_read(pTcpStream,szTmpBuffer,RD_BLOCK_SIZE,4 000);
if(nCnt > 0)
strncpy((char*)szBuffer+i*RD_BLOCK_SIZE,szTmpBuffe r,nCnt);
nBytesReceived += nCnt;
i++;
}
while (nCnt > 0);
FILE* pw = fopen("/user/common/response.xml","w"); // open file
fprintf(pw,"%s",szBuffer); // write file
printf("Bytes received: %d",nBytesReceived);
fclose(pw);
stream_close(pTcpStream);
Kommentar