HttpQueryInfo报错,该怎么处理

php中文网
发布: 2016-06-13 13:18:13
原创
1408人浏览过

HttpQueryInfo报错
file1.php

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->    $file = "D:\ReadFileTo.txt";
    $handle = fopen($file, 'r');
    $sContent = '';
    while(false != ($a = fread($handle, 8080))){//返回false表示已经读取到文件末尾
        $sContent .= $a;
    }
    
    fclose($handle);
    echo "$sContent";
登录后复制


vc(输出file1.php):
C/C++ code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include<windows.h>  
#include<wininet.h>  
#include<iostream.h>  
#pragma comment(lib,"wininet.lib")  

#define DATA_CACHE_SIZE 1024*10
int main(int argc, char* argv[])
{
    printf("Hello World!
");

    int i = 0;
    char pulr[] = "file1.php";
    HINTERNET hinternet=::InternetOpen(
                 "http generic",
                 INTERNET_OPEN_TYPE_PRECONFIG,
                 NULL,    
                 NULL,
                 0);
    if (!hinternet)
    {
        printf("InternetOpen
");
        system("pause");
        return 0;
    }

    i = 1;
    HINTERNET hconnect= ::InternetConnect(
                          hinternet,
                          "144.20.80.27",
                          8080,
                          NULL,                                //lpszUsername
                          NULL,                                //lpszPassword
                          INTERNET_SERVICE_HTTP,
                          0,                                //dwFlags
                          0                                    //dwContext
                          );
    if (!hconnect)
    {
        printf("InternetConnect
");
        system("pause");
        return 0;
    }        

    HINTERNET hHttpOpenRequest=::HttpOpenRequest(
                        hconnect,
                        "POST",
                        pulr,
                        "HTTP/1.1",
                        NULL,
                        0,
                        INTERNET_FLAG_RELOAD,
                        0
            );
    if (!hHttpOpenRequest)
    {
        printf("HttpOpenRequest
");
        system("pause");
        return 0;
    }

    char psHeader[] = "Content-Type: application/x-www-form-urlencoded 

";
    if (!(HttpAddRequestHeaders(
        hHttpOpenRequest, 
        psHeader, 
        strlen(psHeader), 
        HTTP_ADDREQ_FLAG_REPLACE|HTTP_ADDREQ_FLAG_ADD
        )) )
    {
        printf("HttpAddRequestHeaders
");
        system("pause");
        return 0;
    }

    char *strRet=""; //"Yjr|fc|zf|cym|wjf||role1|role2|role3|role4";
    char pstrContent[] = "UserName=admin&amp;Password=-1";
    if (! (HttpSendRequest(
        hHttpOpenRequest,
        NULL,
        0,
        (LPVOID)(LPCSTR)pstrContent,
        strlen(pstrContent)
                    )) )
    {
        printf("HttpSendRequest
");
        system("pause");
        return 0;
    }

    // Get the length of the file.            
    DWORD dwFileSize=0;
    DWORD dwLengthBufQuery = sizeof(dwFileSize);
    DWORD dwIndex=0;
    
    BOOL bQuery = ::HttpQueryInfo(hHttpOpenRequest,
        HTTP_QUERY_CONTENT_LENGTH
        |HTTP_QUERY_FLAG_NUMBER, 
        (LPVOID)&amp;dwFileSize/*bufQuery*/, 
        &amp;dwLengthBufQuery,
        &amp;dwIndex) ;
    if (!bQuery)
    {
        printf("HttpQueryInfo
");
        system("pause");
        return 0;
    }


    // Allocate a buffer for the file.   
    char* buffer = new char[dwFileSize+1] ;
        
    //由于不允许HTTP写缓存,所以无需循环调用InternetReadFile
    DWORD dwLength=0;
    DWORD dwLengthOne=1;
    BOOL bRead=TRUE;
    char bufferOne[DATA_CACHE_SIZE+10];

    strcpy(buffer,"");
    while (bRead &amp;&amp; dwLengthOne&gt;0)
    {
        strcpy(bufferOne,"");
        if (InternetReadFile(
                hHttpOpenRequest,
                bufferOne,
                DATA_CACHE_SIZE+1,
                &amp;dwLengthOne
                )
            ) 
        {
            if (dwLengthOne&gt;0)
            {
                memcpy(&amp;buffer[dwLength],bufferOne,dwLengthOne);
                dwLength+=dwLengthOne;

                //接收数据包的大小和与总数据包大小比较
                if (dwLength &gt; dwFileSize)
                {
                    printf("while
");
                    system("pause");
                    return 0;
                }

                buffer[dwLength]='';
            }
        }
    }
    buffer[dwLength]='';

    //to widerchar
    DWORD dwSize = MultiByteToWideChar (CP_ACP, 0, buffer, -1, NULL, 0);
      WCHAR *wchr = new WCHAR [dwSize];
    ::MultiByteToWideChar(CP_ACP,MB_ERR_INVALID_CHARS,buffer,-1,
                 wchr,dwSize);
    printf(buffer);
//    wprintf(wchr);
    delete [] wchr;
    delete [] buffer;
    
    
    ::InternetCloseHandle(hHttpOpenRequest);hHttpOpenRequest=NULL;

    ::InternetCloseHandle(hconnect);hconnect=NULL;
    ::InternetCloseHandle(hinternet);hinternet=NULL;

    printf("
");
    system("pause");
    return 0;
}
 <div class="clear"></div></iostream.h></wininet.h></windows.h></stdlib.h></stdio.h>
登录后复制
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号