Wie zu tun ist, HTTP-Anfragen mit Android ndk
Schreibe ich eine rein native Anwendung für android/ios und bin Probleme mit dem Netzwerk-code. Ich kann nicht scheinen, um curl zu kompilieren, und so oder so würde ich es vorziehen, haben eine mehr objektorientierte Bibliothek.
Was ist eine gute Bibliothek dazu mit oder Methode? Meine aktuelle Methode, um json-von HTTP-Requests wird dieser code mit 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;
}
};
Dieser bricht bei großen Seiten allerdings.
Du musst angemeldet sein, um einen Kommentar abzugeben.
cURL ist Ihre beste Wette. hier sind ein paar links, die Sie können versuchen, für die Portierung cURL
http://thesoftwarerogue.blogspot.com/2010/05/porting-of-libcurl-to-android-os-using.html
https://github.com/jahrome/curl-android
Wenn Sie noch nicht haben Erfolg mit cURL versuchen POCO
http://pocoproject.org/