套接字打开http url并检索数据
我想打开一个到 http url 的套接字 (https://www.abc.co.uk:8433/open/url/client?username=123&password=456)使用socket.h的socket和connect和recv方法。
问题是 url 使用 8433 端口和剩余的 url (/open/url/client?username=123&password=456)。也使用 https 网址。
有人知道该怎么做吗?很久以前,我已经完成了标准的C 编码,我忘了。
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]);
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]);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要进行 HTTPS 通信,我的猜测是您不想自己实现它 - 或者您希望如何以安全的方式与服务器进行通信?
在这种情况下,我建议您使用 libcurl,它具有出色的协议支持,并且还支持通过 OpenSSL 加密连接。
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.