Example #1
0
std::vector<CGorjunFileInfo>
CRestWorker::get_gorjun_file_info(const QString &file_name) {
  static const QString str_fi("file/info");
  int http_code, err_code, network_error;
  QUrl url_gorjun_fi(CSettingsManager::Instance().gorjun_url().arg(str_fi));
  QUrlQuery query_gorjun_fi;
  query_gorjun_fi.addQueryItem("name", file_name);
  url_gorjun_fi.setQuery(query_gorjun_fi);
  QNetworkRequest request(url_gorjun_fi);
  request.setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
  QByteArray arr = send_get_request(request, http_code, err_code, network_error);
  QJsonDocument doc  = QJsonDocument::fromJson(arr);

  std::vector<CGorjunFileInfo> lst_res;
  if (doc.isNull()) {
    err_code = RE_NOT_JSON_DOC;
    return lst_res;
  }

  if (doc.isArray()) {
    QJsonArray json_arr = doc.array();
    for (auto i = json_arr.begin(); i != json_arr.end(); ++i) {
      if (i->isNull() || !i->isObject()) continue;
      lst_res.push_back(CGorjunFileInfo(i->toObject()));
    }
  } else if (doc.isObject()) {
    lst_res.push_back(CGorjunFileInfo(doc.object()));
  }

  return lst_res;
}
pplx::task<etcd::Response> etcd::Client::watch(std::string const & key, bool recursive)
{
  web::http::uri_builder uri("/v2/keys" + key);
  uri.append_query("wait=true");
  if (recursive)
    uri.append_query("recursive=true");
  return send_get_request(uri);
}
Example #3
0
/**
 *功能:与指定URL站点建立连接,并发出请求
 *参数:@weburl 站点地址
 *返回:如果建立连接成功,返回连接描述符,否则返回-1
 */
int request(char* weburl)
{
	int sockfd;
	int port = 80;
	int web_host_name_length;
	char*web_host, *request_document;

	web_host = request_document = NULL;

	//定位request_document
	if ((request_document = strstr(weburl, "/")) != NULL)
	{
		web_host_name_length = request_document - weburl;

		//定位端口号
		char*port_end;
		if ((port_end = strstr(weburl, ":")) != NULL && port_end
				< request_document)
		{
			port = atoi(port_end + 1);
		}
	}
	else
	{
		web_host_name_length = strlen(weburl);

		//定位端口号
		char*port_end;
		if ((port_end = strstr(weburl, ":")) != NULL)
		{
			port = atoi(port_end + 1);
		}
	}

	web_host = (char*) memory_malloc(sizeof(char) * web_host_name_length + 1);
	strncpy(web_host, weburl, web_host_name_length);
	web_host[web_host_name_length] = '\0';

	if ((sockfd = request_inner(web_host, port)) < 0)
	{
		goto dealfail;
	}

	//请求数据
	if (send_get_request(sockfd, web_host, request_document) < 0)
	{
		goto dealfail;
	}

	free(web_host);
	return sockfd;

	dealfail: free(web_host);
	return -1;

}
Example #4
0
QJsonDocument
CRestWorker::get_request_json_document(const QString &link,
                                       int &http_code,
                                       int &err_code,
                                       int &network_error) {
  QUrl url_env(CSettingsManager::Instance().get_url().arg(link));
  QNetworkRequest req(url_env);
  req.setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
  QByteArray arr = send_get_request(req, http_code, err_code, network_error);
  QJsonDocument doc  = QJsonDocument::fromJson(arr);
  if (doc.isNull()) {
    err_code = RE_NOT_JSON_DOC;
    CApplicationLog::Instance()->LogInfo("Received not json document from url : %s", link.toStdString().c_str());
    return QJsonDocument();
  }
  return doc;
}
int
tool_cmd_get_url(void *thingML_context) {
    ThingMLCOAPContext* context = (ThingMLCOAPContext*) thingML_context;

    get_show_headers = context->client_coap_config.get_show_headers;
    next_len = context->client_coap_config.next_len;
    redirect_count = context->client_coap_config.redirect_count;
    size_request = context->client_coap_config.size_request;
    get_observe = context->client_coap_config.get_observe;
    get_keep_alive = context->client_coap_config.get_keep_alive;
    get_timeout = context->client_coap_config.get_timeout; // Default timeout is 30 seconds.
    last_observe_value = context->client_coap_config.last_observe_value;
    request_accept_type = context->client_coap_config.request_accept_type;
    observe_once = context->client_coap_config.observe_once;
    observe_ignore_first = context->client_coap_config.observe_ignore_first;
    get_tt = context->client_coap_config.get_tt;

    smcp_t gSMCPInstance = smcp_create(((ThingMLCOAPContext*) thingML_context)->port);

    gRet = ERRORCODE_INPROGRESS;
    require(send_get_request(gSMCPInstance, NULL, 0, thingML_context), bail);


    while(ERRORCODE_INPROGRESS == gRet) {
        smcp_wait(gSMCPInstance,1000);
        smcp_process(gSMCPInstance);
    }

bail:
    smcp_transaction_end(gSMCPInstance,&transaction);

    if(gSMCPInstance)
        smcp_release(gSMCPInstance);

    return gRet;
}
Example #6
0
 // Function: send_request
 // Send Request is just an alias for Send GET request.
 bool send_request() const
 { 
    return send_get_request(); 
 }
pplx::task<etcd::Response> etcd::Client::get(std::string const & key)
{
  web::http::uri_builder uri("/v2/keys" + key);
  return send_get_request(uri);
}
pplx::task<etcd::Response> etcd::Client::ls(std::string const & key)
{
  web::http::uri_builder uri("/v2/keys" + key);
  uri.append_query("sorted=true");
  return send_get_request(uri);
}