本文整理汇总了C++中HTTPClient::read方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPClient::read方法的具体用法?C++ HTTPClient::read怎么用?C++ HTTPClient::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPClient
的用法示例。
在下文中一共展示了HTTPClient::read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: make_rpc_req
Json::Value make_rpc_req(Json::Value query, bool logit,unsigned char host,int timeout)
{
HTTPClient cl;
cl.rh["Authorization"] = hosts[host].aut;
cl.rh["Connection"] = "close";
Json::FastWriter writer;
cl.pr["_full_post"] = writer.write(query);
if (logit) {
FILE *fd = fopen(".rpc.log", "w"); // log only 1 transaction
if (fd) {
fprintf(fd, "COMPLETE RPC REQUEST:\n%s\nEND OF REQUEST\n", cl.pr["_full_post"].c_str());
fclose(fd);
}
}
if(timeout){
signal(SIGALRM,connect_alarm);
alarm(timeout);
cl.request(hosts[host].url,true);
alarm(0);}
else{
cl.request(hosts[host].url,true);}
if (!cl.isOK()) {
return Json::Value();
}
std::string ans;
while (cl.peek() != EOF) {
unsigned to_r = cl.rdbuf()->in_avail();
if (to_r == 0) break;
if (to_r > 4000) to_r = 4000;
char tbuf[to_r+2];
cl.read(tbuf,to_r);
ans += std::string(tbuf, to_r);
}
if (logit) {
FILE *fd = fopen(".rpc.log", "a");
if (fd) {
fprintf(fd, "COMPLETE RPC ANSWER:\n%s\nEND OF ANSWER\n", ans.c_str());
fclose(fd);
}
}
cl.disconnect();
Json::Reader reader;
Json::Value answ;
if (!reader.parse(ans, answ)) return false;
if (answ.type() != Json::objectValue) return false;
answ = answ["result"];
if (answ.type() != Json::objectValue) return false;
return answ;
}
示例2: if
int
HTTPClient::clientRead(FILE* stream)
{
if (stream == NULL)
{
return EOF;
}
http_stream_udata* udata = (http_stream_udata*) fdev_get_udata(stream);
HTTPClient* client = udata->client;
if (!client->connected())
{
return EOF;
}
//block until we got a byte
while (client->available() == 0)
{
if (client->connected() == 0)
{
return EOF;
}
};
int result = client->read();
if (result == EOF)
{
return EOF;
}
if (client->debugCommunication)
{
Serial.print((byte) result);
}
//as long as we do not read encoded or it is no % everything is ok
if (udata->encode == 0 || result != '%')
{
return result;
}
else
{
//block until we got the needed bytes
while (client->available() >= 2)
{
if (client->connected() == 0)
{
return EOF;
}
};
char return_value = 0;
for (char i = 0; i < 2; i++)
{
result = client->read();
if (result == EOF)
{
return EOF;
}
else if (result >= 'A' && result <= 'Z')
{
return_value += (1 - i) * 16 * (result - 'A');
}
else if (result >= 'a' && result <= 'z')
{
return_value += (1 - i) * 16 * (result - 'a');
}
else if (result >= '0' && result <= '9')
{
return_value += (1 - i) * 16 * (result - '0');
}
}
return return_value;
}
}