本帖最后由 feethink 于 2010-03-10 21:37:15 编辑

解决方案 »

  1.   

    if (!WinHttpSendRequest(hRequest, 
                    szAdditionalHeader.c_str(), szAdditionalHeader.length(), 
                    (LPVOID)dd, 11,11, 
                    (DWORD_PTR)this))
                {
                    sStatus.szInfo=L"WinHttpSendRequest网址失败!";
                    goto cleanup;
                }
      

  2.   

    楼上的高人?szAdditionalHeader.length() sdk上边没这样说啊.再说那个是消息头.不关form数据的事吧.sdk上说只要设置为-1L.消息头会自动计算的.我试了你那样做.服务器一样没收到..
      

  3.   

    这个函数
    bool CFTHttp::Get(LPWSTR szUrl,LPSTR fileName)
    {
    szFileName=fileName;
    bool bRet=false;
    wstring szAdditionalHeader=L"";//附加头部
    string szFormData="";//表单数据
    WCHAR szHost[256];
    DWORD dwOpenRequestFlag = 0;
    URL_COMPONENTS urlComp;
    bool fRet = false; // Initialize URL_COMPONENTS structure.
    ZeroMemory(&urlComp, sizeof(urlComp));
    urlComp.dwStructSize = sizeof(urlComp); // Use allocated buffer to store the Host Name.
    urlComp.lpszHostName        = szHost;
    urlComp.dwHostNameLength    = sizeof(szHost) / sizeof(szHost[0]); // Set non-zero lengths to obtain pointer a to the URL Path.
    // NOTE: If we threat this pointer as a null-terminated string,
    //       it gives us access to additional information as well. 
    urlComp.dwUrlPathLength = -1; // Crack HTTP scheme.
    urlComp.dwSchemeLength = -1; // Set the szMemo string.
    // Crack the URL.
    if (!WinHttpCrackUrl(szUrl, 0, 0, &urlComp))
    {
    sStatus.szInfo=L"WinHttpCrackUrl分析URL失败.网址可能不正确";
    goto cleanup;
    }
    hConnect = WinHttpConnect(hSession, szHost, 
    urlComp.nPort, 0);
    if (NULL == hSession)
    {
    goto cleanup;
    }
    // Prepare OpenRequest flag
    if (sReqHeader.szVerb==L"POST")
    {
    szAdditionalHeader.append(L"Content-Type: application/x-www-form-urlencoded\r\n");
    }
    dwOpenRequestFlag = (INTERNET_SCHEME_HTTPS == urlComp.nScheme) ? WINHTTP_FLAG_SECURE : 0;
    hRequest=WinHttpOpenRequest(hConnect, 
    sReqHeader.szVerb.c_str(), urlComp.lpszUrlPath,
    NULL, WINHTTP_NO_REFERER, 
    WINHTTP_DEFAULT_ACCEPT_TYPES,
    dwOpenRequestFlag); if (0==hRequest)
    {
    sStatus.szInfo=L"WinHttpOpenRequest打开网址失败!";
    goto cleanup;
    }
    // Install the status callback function.
    WINHTTP_STATUS_CALLBACK pCallback = WinHttpSetStatusCallback(hRequest,
    (WINHTTP_STATUS_CALLBACK)AsyncCallback,
    WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS | 
    WINHTTP_CALLBACK_FLAG_REDIRECT,    
    NULL); // note: On success WinHttpSetStatusCallback returns the previously defined callback function.
    // Here it should be NULL
    if (pCallback != NULL)
    {
    goto cleanup;
    } //prepare additional header

    if (sReqHeader.cCookies!=NULL)
    {
    szAdditionalHeader.append(L"Cookie:");
    szAdditionalHeader.append(sReqHeader.cCookies->CookiesStr);
    szAdditionalHeader.append(L"\r\n");
    }
    if (sReqHeader.szReferer!=L"")
    {
    szAdditionalHeader.append(L"Referer:");
    szAdditionalHeader.append(sReqHeader.szReferer);
    szAdditionalHeader.append(L"\r\n");
    } szFormData.append("xxx=ddd\r\n");  const char *dd=szFormData.c_str();//"xx=ddd你好"; /* const char *d2=new char[7];
     CopyMemory((void *)d2,(void *)dd,7);*/
      //const wchar_t *dd=szFormData.c_str();
      //dd=szFormData.c_str();
    // Send the request.
    if (!WinHttpSendRequest(hRequest, 
    szAdditionalHeader.c_str(),-1L, 
    (void *)dd, 11,11, 
    (DWORD_PTR)this))
    {
    sStatus.szInfo=L"WinHttpSendRequest网址失败!";
    goto cleanup;
    }
    bRet=true;cleanup:
    if (false==bRet)
    {
    Free();
    }
    return bRet;
    }C#里边
       protected override void Render(HtmlTextWriter writer)
        {
          //  Response.ContentEncoding = System.Text.Encoding.UTF8;
            
            string reqHeader;
            reqHeader = Request.Headers.ToString();
            Response.Write("request type\r\n" + Request.RequestType+"\r\n");
            Response.Write("header is :\r\n"+reqHeader+"\r\n");
            Response.Write("type is \r\n" + System.Text.Encoding.Default+ "\r\n");
           // Response.Write(Request.Cookies[0].Name + "--" + Request.Cookies[0].Value+"\r\n|");
           // Response.Write(Request.Cookies[1].Name + "--" + Request.Cookies[1].Value + "\r\n|");
          //  Response.Write("come from :" + Request.UrlReferrer + "\r\n");
            Response.Write("form data count is:" + Request.Form.Count.ToString() + "\r\n");
            Response.Write("form data count is:" + Request.Form.Keys[0] + "\r\n");
        }
      

  4.   

    晚上开始就这问题.还没解决.太郁闷了.要不是操作频繁.我就copymemery算了...哎.
      

  5.   

    有没兴趣加我QQ5 777 63871远程帮我一把?我急用啊.我用的vs2010