46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
#include <f8/internal/pch.h>
|
|
#include <string.h>
|
|
|
|
#include <a8/mutable_xobject.h>
|
|
|
|
#include <f8/jsonhttprequest.h>
|
|
|
|
namespace f8
|
|
{
|
|
|
|
JsonHttpRequest::JsonHttpRequest(unsigned long saddr,
|
|
const std::string url,
|
|
const std::string& query_str,
|
|
a8::CommonCbProc cb)
|
|
{
|
|
saddr_ = saddr;
|
|
url_ = url;
|
|
query_str_ = query_str;
|
|
cb_ = cb;
|
|
params_ = std::make_shared<a8::XObject>();
|
|
resp_xobj_ = a8::MutableXObject::CreateObject();
|
|
|
|
params_->ReadFromUrlQueryString(query_str);
|
|
GetResp()->SetVal("errcode", 0);
|
|
GetResp()->SetVal("errmsg", "");
|
|
}
|
|
|
|
JsonHttpRequest::~JsonHttpRequest()
|
|
{
|
|
Response();
|
|
}
|
|
|
|
void JsonHttpRequest::Response()
|
|
{
|
|
if (!resped_) {
|
|
if (cb_) {
|
|
std::string response;
|
|
resp_xobj_->ToJsonStr(response);
|
|
cb_(a8::Args({a8::HttpResponse(response)}));
|
|
}
|
|
resped_ = true;
|
|
}
|
|
}
|
|
|
|
}
|