Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

InternetReadFile problems

Hello,
I am getting spurious characters in a stream I receive via InternetReadFile(). Here's how I set up the connection:
[code]
hInternet =
InternetOpen(_T("Client"), INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0));
hConnect =
InternetConnect(hInternet, strServer.c_str(),
nPort, _T("Client"), 0, INTERNET_SERVICE_HTTP, 0, lContext)));
hHttp =
HttpOpenRequest(hConnect, _T("POST"), strServlet,
HTTP_VERSION, 0, 0, INTERNET_FLAG_KEEP_CONNECTION, lContext));
HttpSendRequest(hHttp, 0, 0, (void *)strXMLReq.c_str(),
strXMLReq.length());
[/code]
And read the stream:
[code]
char buf[1025];
while (bOK) {
memset((void *) buf, 0, sizeof(buf));
bOK = InternetReadFile(hHttp, (void *) buf,
sizeof(buf) - 1, &bytesRead);
if (bOK) {
if (bytesRead > 0) {
strTemp += buf;
}
else { /* We're done */
break;
}
}
else {
return IDS_ERR_INTERNAL_ERROR_HTTP_READ_FILE;
}
}
[/code]
Unfortunately, random data appears occasionally in the data stream.
Sometimes it is random bytes at the end of the data; sometimes it is junk in the stream. For example:
-74.053096[red]3096[/red]44.436971
Note that the extra 8 bytes are the same as the previous 8 bytes...

Also: why would some calls to InternetReadFile() not get a full buffer's worth of data? While asking for 1024 bytes, sometimes fewer bytes are returned.
TIA for any ideas on what is going wrong.

Comments

  • tipsytipsy Member Posts: 1
    hi,
    I don't know the solution for your problem. rather i have a question of my own.
    how do i download binary files like pdf using HTTP protocol.
    Also is there any way i can know the directory structure(all the files present) in HTTP.
    Thankx

    : Hello,
    : I am getting spurious characters in a stream I receive via InternetReadFile(). Here's how I set up the connection:
    : [code]
    : hInternet =
    : InternetOpen(_T("Client"), INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0));
    : hConnect =
    : InternetConnect(hInternet, strServer.c_str(),
    : nPort, _T("Client"), 0, INTERNET_SERVICE_HTTP, 0, lContext)));
    : hHttp =
    : HttpOpenRequest(hConnect, _T("POST"), strServlet,
    : HTTP_VERSION, 0, 0, INTERNET_FLAG_KEEP_CONNECTION, lContext));
    : HttpSendRequest(hHttp, 0, 0, (void *)strXMLReq.c_str(),
    : strXMLReq.length());
    : [/code]
    : And read the stream:
    : [code]
    : char buf[1025];
    : while (bOK) {
    : memset((void *) buf, 0, sizeof(buf));
    : bOK = InternetReadFile(hHttp, (void *) buf,
    : sizeof(buf) - 1, &bytesRead);
    : if (bOK) {
    : if (bytesRead > 0) {
    : strTemp += buf;
    : }
    : else { /* We're done */
    : break;
    : }
    : }
    : else {
    : return IDS_ERR_INTERNAL_ERROR_HTTP_READ_FILE;
    : }
    : }
    : [/code]
    : Unfortunately, random data appears occasionally in the data stream.
    : Sometimes it is random bytes at the end of the data; sometimes it is junk in the stream. For example:
    : -74.053096[red]3096[/red]44.436971
    : Note that the extra 8 bytes are the same as the previous 8 bytes...
    :
    : Also: why would some calls to InternetReadFile() not get a full buffer's worth of data? While asking for 1024 bytes, sometimes fewer bytes are returned.
    : TIA for any ideas on what is going wrong.
    :

  • Andre YoungAndre Young USAMember Posts: 0

    ____ || http://forcoder.org || free video tutorials and ebooks about { Perl, Visual Basic, Go, R, JavaScript, MATLAB, C++, Assembly, Java, Python, PHP, C, Swift, PL/SQL, Delphi, Objective-C, Scratch, C#, Visual Basic .NET, Ruby Dart, Erlang, Lisp, LabVIEW, Transact-SQL, Scheme, Crystal, F#, Fortran, Kotlin, FoxPro, Logo, Apex, Prolog, Alice, SAS, VBScript, ABAP, Hack, Lua, Clojure, D, Ada, Awk, COBOL, Julia, ML, Rust, Scala, Bash } _

Sign In or Register to comment.