views:

32

answers:

1

I would like to open a socket to http url (https://www.abc.co.uk:8433/open/url/client?username=123&password=456) using socket and connect and recv methods of socket.h.

The problems are that the url is using 8433 port and the remaining url (/open/url/client?username=123&password=456). Also using https url.

Dose anyone know how to do it? Long time ago, I had done the standard C coding, I forget.

int sock;

char url[1024];

struct sockaddr_in client;
struct hostent *h;
if ((sock = socket(AF_INET,SOCK_STREAM,0)) == -1)
{ 
    perror("socket:");
    return;
}

sprintf(url, "https://www.abc.co.uk:%d/open/url/client?username=123&password=456", 8443);

client.sin_family = AF_INET;
client.sin_port = htons(8443);
h = gethostbyname(url);   
client.sin_addr.s_addr = inet_addr(h->h_addr_list[0]);
+3  A: 

If you want to do HTTPS communication, my guess is you don't want to implement it yourself - or how did you expect to communicate in a secure manner with the server?

In this case, I'd recommend you to use libcurl, which has excellent protocol support and also supports encrypted connections via OpenSSL.

Jim Brissom
Agreed - sockets are too low-level for this - you need to implement both SSL and HTTP on top of them. `libcurl` is the right tool.
caf