On 26/07/2016 at 07:13, xxxxxxxx wrote:
User Information:
Cinema 4D Version:
Platform:
Language(s) :
---------
Hi! I'm trying to get a simple HTTP connection working with the c4d_networking API, but I can't
get it to work. While the data appears to be sent correctly (tested with a local webserver and looking
at the logs), I can't get any response.
Here's a very very minimal example that tries to connect to google.com.
void Send(NetworkIpConnection* conn, Char const* string) {
size_t const len = strlen(string);
SendBytes(conn, string, len);
}
void Example() {
NetworkIpAddrPort addr(216, 58, 214, 142, 80); // google.com:80
NetworkIpConnection* conn = OpenOutgoing(addr, nullptr);
if (!conn) {
GePrint("error: could not connect to 216.58.214.142:80");
return;
}
Send(conn, "GET / HTTP/1.1\r\n");
Send(conn, "Host: google.com\r\n");
Send(conn, "\r\n");
Char buffer[8096] = {0};
Int const count = RecvBytes(conn, buffer, sizeof(buffer) - 1);
CloseConnection(conn);
buffer[count] = 0;
GePrint(">>> Response:");
GePrint(String(buffer));
}
RecvBytes() reaches the sessionTimeout of 10 seconds (default in OpenOutgoing()) and returns 0 bytes.
The same works when I do it eg. from Python:
>>> import socket
\>>> s = socket.socket()
\>>> s.connect(('216.58.214.142', 80))
\>>> s.send(b'GET / HTTP/1.1\r\nr"')
18
\>>> s.send(b'Host: google.com\r\n')
18
\>>> s.send(b'\r\n')
2
\>>> s.recv(8000)
b'HTTP/1.1 302 Found\r\nCache-Control: private\r\nContent-Type: text/html; charset=UTF-8\r\nLocation: http://www.google.de/?gfe_rd=cr&ei=2G6XV_SrI4WQ8QeR94DwDw\r\nContent-Length: 258\r\nDate: Tue, 26 Jul 2016 14:08:24 GMT\r\n\r\n<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">\n<TITLE>302 Moved</TITLE></HEAD><BODY>\n<H1>302 Moved</H1>\nThe document has moved\n<A HREF="http://www.google.de/?gfe_rd=cr&ei=2G6XV_SrI4WQ8QeR94DwDw">here</A>.\r\n</BODY></HTML>\r\n'
What am I doing wrong?
Thanks in advance,
Niklas