我遇到了一个问题,当试图在头发送证书。这是我的代码
PCCERT_CONTEXT pccertContext = GetCertificate();
DWORD size = 0;
CryptBinaryToString(pccertContext->pbCertEncoded, pccertContext->cbCertEncoded, CRYPT_STRING_BASE64, NULL, &size);
LPTSTR dest = static_cast<LPTSTR> (HeapAlloc(GetProcessHeap(), HEAP_NO_SERIALIZE, size * sizeof(TCHAR)));
CryptBinaryToString(pccertContext->pbCertEncoded, pccertContext->cbCertEncoded, CRYPT_STRING_BASE64, dest, &size);
HeapFree(GetProcessHeap(), HEAP_NO_SERIALIZE, dest);
http_request request(methods::GET);
request.headers().add(L"client-certificate", dest);
request.set_request_uri(getUri());
client::http_client client(web::uri(StringUtils::ToWString(*url)), config);
const auto response = client.request(request).get();
当我尝试发出请求时,它失败了。感谢任何关于我哪里出错的帮助。谢谢!
找到问题了。Dest是一个多行字符串。这就是http_request拒绝报头的原因。做了以下修复:
wstring ws(dest);
ws.erase(remove(ws.begin(), ws.end(), 'r'), ws.end());
ws.erase(remove(ws.begin(), ws.end(), 'n'), ws.end());
// Send ws in the header instead
http_request request(methods::GET);
request.headers().add(L"client-certificate", ws);
request.set_request_uri(getUri());
client::http_client client(web::uri(StringUtils::ToWString(*url)), config);
const auto response = client.request(request).get();