Answer the question
In order to leave comments, you need to log in
InternetReadFile adds heresy to the end of the line. What to do?
Hello.
There is a built-in Requests class.
I use the GetRequest function in it.
Actually, here she is:
string GetRequest(string url, string path = "", string ContentType = "") {
InternetSetOption(0, 42, NULL, 0);
HINTERNET hSocket = InternetOpen(TEXT("FORMATC"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL);
if (hSocket != NULL) {
HINTERNET hConnection = InternetConnect(hSocket, TEXT(url.c_str()), INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
if (hConnection != NULL) {
HINTERNET hRequest;
if (path == "") {
hRequest = HttpOpenRequest(hConnection, TEXT("GET"), NULL, NULL, NULL, 0, INTERNET_FLAG_RELOAD | INTERNET_FLAG_SECURE, 1);
}
else {
hRequest = HttpOpenRequest(hConnection, TEXT("GET"), TEXT(path.c_str()), NULL, NULL, 0, INTERNET_FLAG_RELOAD | INTERNET_FLAG_SECURE, 1);
}
if (hRequest != NULL) {
if (ContentType == "") {
HttpSendRequest(hRequest, NULL, 0, NULL, 0);
}
else {
HttpSendRequest(hRequest, ContentType.c_str(), ContentType.length(), NULL, NULL);
}
char strContent[1024];
DWORD dwByteRead;
InternetReadFile(hRequest, strContent, sizeof(strContent) - 1, &dwByteRead);
return string(strContent);
}
InternetCloseHandle(hRequest);
}
InternetCloseHandle(hConnection);
}
InternetCloseHandle(hSocket);
return "";
}
{"response":"ok"}
{"response":"ok"}
, but this one: {"response":"ok"}(*@D
. Well, there are not such symbols, but I think you understand. In general, because of these characters, nlohmann::json crashes, and I cannot parse normally. Help what to do? Answer the question
In order to leave comments, you need to log in
Ahem-ahem...
I should probably go to bed, it's 5 o'clock in the morning, after all.
The solution came immediately when I looked at the array.
It was declared like this:
strContent[1024];
In fact, there is nothing there, so it was enough to fill it with zeros:
strContent[1024] = {0};
And it all worked.
Do not regard it as spam, I was just inattentive, but I'll leave the decision, all of a sudden someone will also have this.
Wrong You have chosen a solution to the problem.
InternetReadFile(hRequest, strContent, sizeof(strContent)/* - 1*/, &dwByteRead);
return string(strContent, dwByteRead);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question