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;
}
函数功能:发送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;
}
相关文章推荐
- use c to send file using http post
- C++ ws2_32封装http请求,支持http get、post、filedown,解决请求编码问题
- How to use HttpWebRequest to post data to another page which is on another server
- how to use the X file (C++/DirectX)
- Csharp:WebClient and WebRequest use http download file
- C++实现Http Post请求
- 使用file_get_contents提交http post
- mfc,C++,HTTP,POST方式提交请求
- 通过POST向WEB服务器发送数据/上传文件(HttpSendRequestEx、InternetWriteFile)
- c++如何使用SOCKET 发送HTTP1.1 GET POST请求包
- How to use HttpWebRequest to send POST request to another web server?
- Use Http Post to call Web Service
- HttpUploadFile模拟前台POST上传图片和后台获取上传图片并上传至服务器
- C++实现Http Post请求
- PHP http(file_get_content) GET与POST请求方式
- httpClient4.3 模拟Post提交,模拟Post上传文件并解决服务端使用spingMVC时upload.parseRequest(request)解析不到File,Pos简单抓取页面数据
- C++ 之HTTP post请求
- Csharp:WebClient and WebRequest use http download file
- C++通过HTTP请求Get或Post方式请求Json数据
- C++ 简单实现HTTP GET/POST 请求