1
나는 안드로이드/ios 용 순수 네이티브 애플리케이션을 작성 중이며 네트워킹 코드에 문제가 있습니다. 컴파일 할 때 곱슬 곱슬 해지는 느낌이 들지 않으며, 어느 쪽의 방법이라도 객체 지향 라이브러리를 더 많이 갖고 싶습니다.Android ndk로 HTTP 요청을하는 방법
이 작업을 수행하기에 좋은 라이브러리는 무엇입니까? 현재 HTTP 요청에서 json을 얻는 방법은 SDL2_Net을 사용하는이 코드입니다.
class HTTPRequest{
protected:
std::map<std::string, std::string> uris;
std::string url;
public:
std::string host;
HTTPRequest(std::string path) : url(path), host("182.50.154.140") {}
void addURI(std::string parameter, std::string value){
uris[parameter] = value;
}
std::string sendRequest(bool useCookie=false){
std::string temppath = url;
if(!uris.empty()){
temppath += '?';
for(auto &a : uris){
temppath += a.first;
temppath += '=';
temppath += a.second;
temppath += '&';
}
}
IPaddress* addr = new IPaddress;
SDLNet_ResolveHost(addr, host.c_str(), 8080);
TCPsocket sock = SDLNet_TCP_Open(addr);
std::string a = "GET ", b = " HTTP/1.1\r\nHost: 182.50.154.140:8080\r\nConnection: close\r\n\r\n";
std::string c = a+temppath+b;
SDLNet_TCP_Send(sock, c.c_str(), c.length());
std::string d;
char* buf = new char[1024];
while(SDLNet_TCP_Recv(sock, buf, 1024) > 0){
d += buf;
delete[] buf;
buf = new char[1024];
}
delete[] buf;
SDLNet_TCP_Close(sock);
int p = d.find("{");
d.erase(0, p-1);
return d;
}
};
큰 페이지에서는이 문제가 발생합니다.
을 시도하다 실제로 사용하여 컴파일 컬 얻을 수 있었다 이 사이트에 대한 또 다른 대답은 최신 버전으로 작업 할 수 있도록 명령을 수정해야한다는 것입니다. – ruler501