I tried to implemented login in c++. But it says “401 unauthorization”.
I think something is wrong in header setting.
this is documentation you provided.
POST /ServerAPI/ServerCommandService.asmx HTTP/1.1
Host: {xprotectserver.company.com}
Authorization: {autogenerated by HTTP library or class applied}
Content-Type: text/xml; charset=utf-8
Content-Length: {number of bytes}
SOAPAction: http://videoos.net/2/XProtectCSServerCommand/Login"
How should I set Authorization header ?
{autogenerated by HTTP library or class applied} doesn’t make sense for me.
the following code is what I coded.
IdHTTP1->Request->Accept = “text/xml”;
IdHTTP1->Request->Host = sServerIP.c_str();
IdHTTP1->Request->BasicAuthentication = false;
IdHTTP1->Request->ContentEncoding = “utf-8”; //in test
IdHTTP1->Request->ContentType = “text/xml; charset=utf-8”; IdHTTP1->Request->ContentLength = sSoap.length();
IdHTTP1->Request->Method = “POST”;
IdHTTP1->Request->Username = sUsername.c_str();
IdHTTP1->Request->Password = sPassword.c_str();
IdHTTP1->Request->UserAgent = “IndyTest”;
IdHTTP1->Request->CustomHeaders->AddValue(“SOAPAction”, sSoapAction.c_str());
TStringStream *pReq = new TStringStream(UnicodeString(sSoap.c_str()), TEncoding::UTF8, true);
TStringStream *pResp = new TStringStream();
IdHTTP1->Post(sURL.c_str(), pReq, pResp);
IdHTTP1->Request->CustomHeaders->Clear();
oss << IdHTTP1->ResponseCode << “\”" << AnsiString(IdHTTP1->Response->ResponseText).c_str() << “\”";