windows c socket()失败,获取通信端口失败,是什么原因
发布网友
发布时间:2022-04-25 04:02
我来回答
共1个回答
热心网友
时间:2023-10-24 17:23
#pragma comment(lib,"WS2_32.LIB")
WSADATA ws;
WSAStartup(MAKEWORD(2,0),&ws);
int res_socket, res, on;
struct sockaddr_in address;
struct in_addr in_ip;
res = res_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
WSACleanup();
可以这样获取网页源码(C#版)
WebClient wClient = new WebClient();
wClient.BaseAddress = txtName.Text;
wClient.Encoding = Encoding.UTF8;
wClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");
Stream stream = wClient.OpenRead(txtName.Text); //txtName.Text为一个标准的http网址,例如:http://www.baidu.com
StreamReader Sr = new StreamReader(stream);
string str = string.Empty;
while ((str = Sr.ReadLine()) != null)
{
lsBox.Items.Add(str);
}
wClient.DownloadFile(txtName.Text,"hello.txt");