原贴 http://bbs.csdn.net/topics/390508313
有人发个地址让参考 http://blog.csdn.net/yc0188/article/details/4741871
实在没看明白怎么传参使用它,哪位大哥能说一下如何用这个函数吗,能发个例子给我是最好的。解决问题分数一并送上。
环境 vs2010 程序
[email protected] 示例代码:
void MEF_Set_Http_Header(MEF_Http_Action_t method, S8 * action, S8 * server, S8 * msg_body, S8 * head, U8 connect_type)
{
S8 tmp_buf[20];
const S8 * http_methods_table[MEF_TOTAL_HTTP_ACTIONS] = {"GET", "POST", "HEAD", "PUT", "OPTIONS", "DELETE", "TRACE", "CONNECT"}; sprintf(head,"%s ", http_methods_table[method]);
if(action)
{
strcat(head, action);
} strcat(head," HTTP/1.1");
strcat(head,"/r/n"); strcat(head,"Accept:*/*");
strcat(head,"/r/n"); strcat(head,"User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
strcat(head,"/r/n"); strcat(head,"Host: ");
strcat(head,server);
strcat(head,"/r/n"); if(method == MEF_HTTP_POST)
{
strcat(head,"Content-Type: application/x-www-form-urlencoded");
strcat(head,"/r/n");
} if(method == MEF_HTTP_POST)
{
strcat(head, "Content-Length: ");
sprintf(tmp_buf, "%d", strlen(msg_body));
strcat(head, tmp_buf);
strcat(head,"/r/n");
}
if(connect_type == 1)
strcat(head,"Connection: Keep-Alive");
else
strcat(head,"Connection: close");
strcat(head,"/r/n");
strcat(head,"/r/n");
if(method == MEF_HTTP_POST)
{
if(msg_body)
{
strcat(head,msg_body);
}
}
}
有人发个地址让参考 http://blog.csdn.net/yc0188/article/details/4741871
实在没看明白怎么传参使用它,哪位大哥能说一下如何用这个函数吗,能发个例子给我是最好的。解决问题分数一并送上。
环境 vs2010 程序
[email protected] 示例代码:
void MEF_Set_Http_Header(MEF_Http_Action_t method, S8 * action, S8 * server, S8 * msg_body, S8 * head, U8 connect_type)
{
S8 tmp_buf[20];
const S8 * http_methods_table[MEF_TOTAL_HTTP_ACTIONS] = {"GET", "POST", "HEAD", "PUT", "OPTIONS", "DELETE", "TRACE", "CONNECT"}; sprintf(head,"%s ", http_methods_table[method]);
if(action)
{
strcat(head, action);
} strcat(head," HTTP/1.1");
strcat(head,"/r/n"); strcat(head,"Accept:*/*");
strcat(head,"/r/n"); strcat(head,"User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
strcat(head,"/r/n"); strcat(head,"Host: ");
strcat(head,server);
strcat(head,"/r/n"); if(method == MEF_HTTP_POST)
{
strcat(head,"Content-Type: application/x-www-form-urlencoded");
strcat(head,"/r/n");
} if(method == MEF_HTTP_POST)
{
strcat(head, "Content-Length: ");
sprintf(tmp_buf, "%d", strlen(msg_body));
strcat(head, tmp_buf);
strcat(head,"/r/n");
}
if(connect_type == 1)
strcat(head,"Connection: Keep-Alive");
else
strcat(head,"Connection: close");
strcat(head,"/r/n");
strcat(head,"/r/n");
if(method == MEF_HTTP_POST)
{
if(msg_body)
{
strcat(head,msg_body);
}
}
}
楼主以后遇到这种问题不要相信这些人,去codeproject上面看看,有很多好用的类和示范projecthttp://www.codeproject.com/Articles/7828/CHttpClient-A-Helper-Class-Using-WinInet