📄 httpoperation.c
字号:
/*
* This sample code is written by block mode. If you want to use nonblock mode,
* please reference the HttpOperation_NonBlock sample.
*
* The corresponding URL commands can be found in appendix of user manual.
*
*/
#include "Utility.h"
int main(int argc, char* argv[])
{
SCODE scRet = S_OK;
HANDLE hServerMgr = NULL;
HANDLE hDevice = NULL;
TCHAR szModelName[MAX_PATH] = {0};
TSERVER_INFO tServerInfo;
// Http operation parameters
BYTE byDataBuf[MAX_PATH];
DWORD dwBufLength = MAX_PATH;
HANDLE hOperation;
// example HTTP Read command input: -I192.168.0.1 -H80 -Uroot -Proot -T30000 -C/cgi-bin/admin/getparam.cgi?system_hostname -R
// example HTTP Write command input: -I192.168.0.1 -H80 -Uroot -Proot -T30000 -C/cgi-bin/admin/setparam.cgi?system_hostname=test
if (ParseInputArgument(argc, argv, &tServerInfo, eSrvMgrHTTPOperation) != S_OK)
{
return 0;
}
// 1. Initialization
scRet = ServerManagerInitBlock(&hServerMgr, &hDevice, szModelName, tServerInfo);
if (S_OK != scRet)
{
printf("ServerManagerInitBlock failed...\n");
return 0;
}
// 2. HTTP Operation sample
if (tServerInfo.bRead)
{
// HTTP Read command
scRet = ServerManager_SendHttpCommandReadBlock(hDevice, tServerInfo.tHttpOperation.szUrlCommand, tServerInfo.tHttpOperation.bPost, byDataBuf, &dwBufLength, &hOperation);
if (S_OK == scRet)
{
printf("Send HTTP command success.\n%s\n", byDataBuf);
}
}
else
{
// HTTP Write command
scRet = ServerManager_SendHttpCommandBlock(hDevice, tServerInfo.tHttpOperation.szUrlCommand, tServerInfo.tHttpOperation.bPost);
if (S_OK == scRet)
{
printf("Send HTTP command success.\n");
}
}
if (S_OK != scRet)
{
printf("Send HTTP command failed: %X\n", scRet);
}
// 3. Release all resource
ServerManagerRelease(&hServerMgr, &hDevice);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -