您的位置:首页 > 理论基础 > 计算机网络

use c++ http post file

2007-10-23 10:44 302 查看
/*-------------------------------------------------------------------------------------------------------------------

函数功能:发送HTTP头

参 数:sockfd 服务器句柄;

head HTTP头

返回值: 成功返回0,失败返回错误代码

--------------------------------------------------------------------------------------------------------------------*/

int SendHttpHead(int sockfd, HTTPHEAD head)

{

char data[100];

char dataEnc[100];

char httphead[500] = "POST ";

strcat(httphead, head.servicename);

strcat(httphead, " HTTP/1.0\n");

strcat(httphead, "Connection: keep-alive\n");

strcat(httphead, "Content-Type: text/html; charset=\"gb2312\"\n");

strcat(httphead, "Content-Length: ");

strcat(httphead, head.ContentLength);

strcat(httphead, "\n");

strcat(httphead, "Host: ");

strcat(httphead, head.HostIP);

strcat(httphead, ":");

strcat(httphead, head.HostPort);

strcat(httphead, "\n");

strcat(httphead, "Accept: text/html, */*\n");

strcat(httphead, "User-Agent: Mozilla/3.0 (compatible; Indy Library)\n");

strcat(httphead, "Authorization: Basic ");

strcpy(data, head.TaxPayerNO);

strcat(data, ":");

strcat(data, "888888\n");

Base64_Enc(dataEnc, data, strlen(data));

strcat(httphead, dataEnc);

strcat(httphead, "proxy-Authorization: Basic Og==\n");

if ( send(sockfd, httphead, strlen(httphead) ,0) == -1 )

{

return -1;

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: