[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
URLStream::post
From: |
David Genest |
Subject: |
URLStream::post |
Date: |
Sat, 31 Aug 2002 16:06:56 +0200 |
Hi,
I think there is a bug in the URLStream::post() method (CommonC++2,
1.0.0 on Debian i386, g++ 2.95.4, also with Borland C++ 5.5.1). In fact,
post() doesn't send arguments because a separator is written after
"Content-Length:...".
More precisely, CommonC++2 uses ostringstream (whereas CommonC++1 uses
strsteam), and "ends" is not needed with ostringstream (whereas it is
with strstream). See for ex. http://www.freshsources.com/newcpp.html.
So, line 530 of url.cpp (str << "\r\n" << ends;) is wrong because str is
an ostringstream, and we have to change this line :
str << "\r\n";
Here is a sample of code (based on demo/urlfetch.cpp) showing the
problem. This program submits a "post" query to search.apache.org.
Without this change, this code displays a page without results (args are
not sent), whereas with this change, it displays the results of the
search.
#include <cc++/common.h>
#include <iostream>
int main(int argc, char **argv)
{
ost::URLStream url;
ost::URLStream::Error status;
char cbuf[1024]; int len;
const char * args[5];
args[0] = "keyword=httpd.conf";
args[1] = "what=httpd.apache.org";
args[2] = "results=20"; args[3] = "version=2";
args[4] = NULL;
status = url.post("http://search.apache.org/";, args);
while(!url.eof())
{
url.read(cbuf, sizeof(cbuf));
len = url.gcount();
if(len > 0) std::cout.write(cbuf, len);
}
url.close();
return 0;
}
David.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- URLStream::post,
David Genest <=