CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2010
    Posts
    38

    how insert data in my code?

    Dear Sirs,
    I am using WinHttp for connecting to server from C++.
    I can connect to sever correctly but I have not experience for set my requested items for sending to server and get response from server.
    I have problem for setting below function:

    httpResult = WinHttpSendRequest( hRequest, WINHTTP_NO_ADDITIONAL_HEADERS,
    0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
    httpResult = WinHttpReceiveResponse( hRequest, NULL);

    Can anybody help me for making correct setting in this code?

    Thanks.

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: how insert data in my code?

    You seem to be missing the HttpOpenRequest() which is where the guts of the request are specified.

  3. #3
    Join Date
    May 2010
    Posts
    38

    Re: how insert data in my code?

    Quote Originally Posted by hoxsiew View Post
    You seem to be missing the HttpOpenRequest() which is where the guts of the request are specified.
    Dear sir,
    thank you for your reply.
    my code is as below:

    // 111.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include <windows.h>

    #include <winhttp.h>

    #include <stdio.h>
    #include <conio.h>



    int main(int argc, char* argv[])
    {
    HINTERNET hSession;
    HINTERNET hConnect;
    HINTERNET hRequest;
    BOOL httpResult;
    DWORD data;
    DWORD dwSize = sizeof(DWORD);
    LPWSTR pwszURL;


    // Print a description of the sample.
    printf("This sample demonstrates the process for retrieving WinHTTP\n");
    printf("options programmatically from a C/C++ application. WinHTTP\n");
    printf("application programming interface (API) functions are used to\n");
    printf("determine the default connect time-out value and to find the\n");
    printf("current URL after an HTTP request is redirected.\n\n");

    // Use WinHttpOpen to obtain a session handle.
    hSession = WinHttpOpen( L"A WinHTTP Example Program/1.0",
    WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
    WINHTTP_NO_PROXY_NAME,
    WINHTTP_NO_PROXY_BYPASS, 0);

    // Use WinHttpQueryOption to retrieve Internet options.
    httpResult = WinHttpQueryOption( hSession, WINHTTP_OPTION_CONNECT_TIMEOUT,
    &data, &dwSize);
    if (httpResult)
    printf("Connect time-out:\t%u ms\n",data);

    // Use WinHttpConnect to specify an HTTP server.
    hConnect = WinHttpConnect( hSession, L"raoof.net",
    INTERNET_DEFAULT_HTTP_PORT, 0);

    // Open and Send a Request Header.
    hRequest = WinHttpOpenRequest( hConnect, L"GET",
    L"/time.php",
    NULL, WINHTTP_NO_REFERER,
    WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
    httpResult = WinHttpSendRequest( hRequest, WINHTTP_NO_ADDITIONAL_HEADERS,
    0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
    httpResult = WinHttpReceiveResponse( hRequest, NULL);

    // Use WinHttpQueryOption again, this time to obtain a buffer size.
    httpResult = WinHttpQueryOption( hRequest, WINHTTP_OPTION_URL,
    NULL, &dwSize);
    pwszURL = new WCHAR[dwSize/sizeof(WCHAR)];

    // Use WinHttpQueryOption to retrieve Internet options.
    httpResult = WinHttpQueryOption( hRequest, WINHTTP_OPTION_URL,
    (void *)pwszURL, &dwSize);
    printf("Redirected URL:\t\t%S\n",pwszURL);

    // Free the allocated memory.
    delete [] pwszURL;

    // When finished, release the hRequest handle.
    httpResult = WinHttpCloseHandle(hRequest);
    if (!httpResult)
    printf("Could not close the hRequest handle.\n");

    // When finished, release the hConnect handle.
    httpResult = WinHttpCloseHandle(hConnect);
    if (!httpResult)
    printf("Could not close the hConnect handle.\n");

    // When finished, release the hSession handle.
    httpResult = WinHttpCloseHandle(hSession);
    if (!httpResult)
    printf("Could not close the hSession handle.\n");
    getch();

    return 0;
    }




    I want know how must read url?

    thanks.

  4. #4
    Join Date
    Feb 2005
    Posts
    2,160

    Re: how insert data in my code?

    Please use code tags!

    type this:

    [code]
    //type your code here
    int main()...
    [/code]

    to get this

    Code:
      //type your code here
      int main()...

    What do you mean by "read the url"? If you want to get the raw html from a request, use InternetReadFile().

    In general your steps should be:

    • InternetOpen
    • InternetConnect
    • HttpOpenRequest
    • HttpSendRequest
    • InternetReadFile

  5. #5
    Join Date
    May 2010
    Posts
    38

    Re: how insert data in my code?

    Quote Originally Posted by hoxsiew View Post
    Please use code tags!

    type this:

    [code]
    //type your code here
    int main()...
    [/code]

    to get this

    Code:
      //type your code here
      int main()...

    What do you mean by "read the url"? If you want to get the raw html from a request, use InternetReadFile().

    In general your steps should be:

    • InternetOpen
    • InternetConnect
    • HttpOpenRequest
    • HttpSendRequest
    • InternetReadFile
    Dear sir,
    Thank you for your email.
    For first step I want open one url and read time from that and use that in my code.
    my url is: www.raoof.net/time.php

    So how I must use this code.

    Another thing I using Win32 application for making dll for my Metatrader software.
    It is possible collect all codes in one dll?

    Best Regards,

  6. #6
    Join Date
    May 2010
    Posts
    38

    Re: how insert data in my code?

    Dear Sirs,
    Thank you for your helping,
    Finally I succeed read data from my webpage.
    My webpage send date as "1273253763" tome.
    I found I received this number as const char* and it is not int or double number.
    I want know how I can convert that to int or double number?

    Thanks.

  7. #7
    Join Date
    Feb 2005
    Posts
    2,160

    Re: how insert data in my code?

    strtol(), strtoul(), strtod(), or atoi().

    http://msdn.microsoft.com/en-us/library/ms860466.aspx

  8. #8
    Join Date
    May 2010
    Posts
    38

    Re: how insert data in my code?

    Quote Originally Posted by hoxsiew View Post
    strtol(), strtoul(), strtod(), or atoi().

    http://msdn.microsoft.com/en-us/library/ms860466.aspx
    Dear hoxsiew,
    Thank you.
    Now it working.
    Best Regards,

  9. #9
    Join Date
    May 2010
    Posts
    38

    Re: how insert data in my code?

    Dear Sirs,
    Thank you for your helping.
    I made above code for using in other my C++ dll code.
    I tried mixed two code in one code and using result above code for second my dll.
    I tried but not succeed.
    My code that I using for dll is as below:


    //+------------------------------------------------------------------+
    //| Sample DLL for MQL4 |
    //| Copyright © 2004-2006, MetaQuotes Software Corp. |
    //| http://www.metaquotes.net |
    //+------------------------------------------------------------------+
    #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
    #include <windows.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include "stdafx.h"
    #include <fstream>
    #include <sstream>
    #include <iostream>
    #include <string.h>
    #include <time.h>
    #include <conio.h>

    #include <winhttp.h>



    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;

    #endif
    //----
    #define MT4_EXPFUNC __declspec(dllexport)
    //+------------------------------------------------------------------+
    //| |
    //+------------------------------------------------------------------+






    MT4_EXPFUNC char* __stdcall Get_Account_Number()
    {
    return("7606231");
    }

    MT4_EXPFUNC bool __stdcall Account_Validation()
    {
    char* A_N;
    A_N = Get_Account_Number();
    stringstream Middle_C;
    string Account_Number;
    Middle_C << A_N;
    Middle_C >> Account_Number;
    HWND mainwindow;
    char text[MAX_PATH];
    mainwindow = GetForegroundWindow();
    GetWindowText(mainwindow,text,sizeof(text));
    stringstream Middle_Convert;
    string Window_Title;
    Middle_Convert << text;
    Middle_Convert >> Window_Title;
    size_t pos;
    pos = Window_Title.find(Account_Number);
    time_t seconds;
    seconds = time (NULL);

    if (pos!=(-1) && seconds<1293861600)
    {
    return(true);
    }
    else
    {
    return(false);
    }
    }


    MT4_EXPFUNC char* __stdcall Get_Signal(double S1, double S2, double S3, double S4, double S5, double S6, double S7, double S8, double S9, double S10, double S11, double S12, double S13, double S14, double S15, double S16, double S17, double S18, double S19, double S20, double S21, double S22, double S23, double S24, double S25, double S26, double S27, double S28, double S29, double S30, double S31, double S32, double S33, double S34, double S35, double S36, double S37, double S38, double S39, double S40, double S41, double S42, double S43, double S44, double S45)
    {
    char* A_N;
    A_N = Get_Account_Number();
    stringstream Middle_C;
    string Account_Number;
    Middle_C << A_N;
    Middle_C >> Account_Number;
    HWND mainwindow;
    char text[MAX_PATH];
    mainwindow = GetForegroundWindow();
    GetWindowText(mainwindow,text,sizeof(text));
    stringstream Middle_Convert;
    string Window_Title;
    Middle_Convert << text;
    Middle_Convert >> Window_Title;
    size_t pos;
    pos = Window_Title.find(Account_Number);
    time_t seconds;
    seconds = time (NULL);
    if (pos!=(-1) && seconds<1293861600)
    {
    if ((S39> 95) )
    {
    return("Sell");
    }
    if ((S39< 5))
    {
    return("Buy");
    }
    }
    else
    {
    return("Forbiden");
    }
    }


    I am trying use result from code that connect to server in this code.
    I have problem for mix these codes. When I using both code together I find errors.
    Please help it is possible mix both?

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured