当前位置: 首页>>代码示例>>C++>>正文


C++ HttpRequest::AddHeader方法代码示例

本文整理汇总了C++中HttpRequest::AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpRequest::AddHeader方法的具体用法?C++ HttpRequest::AddHeader怎么用?C++ HttpRequest::AddHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpRequest的用法示例。


在下文中一共展示了HttpRequest::AddHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AddHeaders

/**
 * Called by MHD_get_connection_values to add headers to a request obect.
 * @param cls a pointer to an HttpRequest object.
 * @param key the header name
 * @param value the header value
 */
static int AddHeaders(void *cls, enum MHD_ValueKind kind, const char *key,
                      const char *value) {
  HttpRequest *request = static_cast<HttpRequest*>(cls);
  string key_string = key;
  string value_string = value;
  request->AddHeader(key, value);
  return MHD_YES;
  (void) kind;
}
开发者ID:huyanming,项目名称:open-lighting,代码行数:15,代码来源:HttpServer.cpp

示例2: Parse


//.........这里部分代码省略.........

        switch (nextChar) {
          case '\0':
            status = FINISHED;
          break;

          case '\r':
            currentPos++;
          break;

          case '\n':
            http.m_start = start;
            http.m_length = pieceLen;

            currentPos++;

            start = &requestString[currentPos];
            pieceLen = 0;

            status = HEADER;
          break;

          default:
            pieceLen++;
            currentPos++;
          break;
        }
      }
      break;

      case HEADER: {
        char nextChar = getChar(requestString, currentPos);

        switch (nextChar) {
          case '\0':
            status = FINISHED;
          break;

          case '\r':
            currentPos++;
          break;

          case '\n': {
            StringPiece header;
            header.m_start = start;
            header.m_length = pieceLen;

            request.AddHeader(header);

            currentPos++;

            start = &requestString[currentPos];
            pieceLen = 0;

            status = HEADER_NEWLINE;
          }
          break;

          default:
            pieceLen++;
            currentPos++;
          break;
        }
      }
      break;

      case HEADER_NEWLINE: {
        char nextChar = getChar(requestString, currentPos);

        switch (nextChar) {
          case '\r':
            currentPos++;
          break;

          case '\n':
            status = FINISHED;
          break;

          default:
            status = HEADER;
          break;
        }
      }
      break;

      default:
        status = MORE_DATA;
      break;
    }
  }

  HttpRequestParser::ParseRes out(status, currentPos);

  request.set_request_method(MethodFromStringPiece(method));
  request.set_resource_path(url);
  request.set_http_ver(HttpVerFromStringPiece(http));
  request.set_parse_res(out);

  return out;
}
开发者ID:Olster,项目名称:ModServer,代码行数:101,代码来源:request.cpp

示例3: RequestAcceessTokenAsync

UINT CDropbox::RequestAcceessTokenAsync(void *owner, void* param)
{
	HWND hwndDlg = (HWND)param;
	CDropbox *instance = (CDropbox*)owner;

	EnableWindow(GetDlgItem(hwndDlg, IDC_AUTHORIZE), FALSE);
	SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("in process..."));

	if (instance->HasAccessToken())
		instance->DestroyAcceessToken();

	char requestToken[128];
	GetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, requestToken, SIZEOF(requestToken));

	char data[1024];
	mir_snprintf(
		data,
		SIZEOF(data),
		"grant_type=authorization_code&code=%s",
		requestToken);

	HttpRequest *request = new HttpRequest(instance->hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/oauth2/token");
	request->AddBasicAuthHeader(DROPBOX_API_KEY, DROPBOX_API_SECRET);
	request->AddHeader("Content-Type", "application/x-www-form-urlencoded");
	request->pData = mir_strdup(data);
	request->dataLength = (int)strlen(data);

	mir_ptr<NETLIBHTTPREQUEST> response(request->Send());

	delete request;

	MCONTACT hContact = instance->GetDefaultContact();

	if (response)
	{
		JSONROOT root(response->pData);
		if (root)
		{
			if (response->resultCode == HTTP_STATUS_OK)
			{
				JSONNODE *node = json_get(root, "access_token");
				ptrA access_token = ptrA(mir_u2a(json_as_string(node)));
				db_set_s(NULL, MODULE, "TokenSecret", access_token);

				if (hContact)
				{
					if (db_get_w(hContact, MODULE, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
						db_set_w(hContact, MODULE, "Status", ID_STATUS_ONLINE);
				}

				instance->RequestAccountInfo();

				if (hwndDlg)
					SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("you have been authorized"));
				/*else
					ShowNotification(TranslateT("you have been authorized"), MB_ICONINFORMATION);*/
			}
			else
			{
				JSONNODE *node = json_get(root, "error_description");
				ptrW error_description(json_as_string(node));

				if (hwndDlg)
					SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, error_description);
				/*else
					ShowNotification((wchar_t*)error_description, MB_ICONERROR);*/
			}
		}
	}
	else
	{
		if (hwndDlg)
			SetDlgItemText(hwndDlg, IDC_AUTH_STATUS, TranslateT("server does not respond"));

		HandleHttpResponseError(instance->hNetlibUser, response);
	}

	SetDlgItemTextA(hwndDlg, IDC_REQUEST_CODE, "");

	return 0;
}
开发者ID:martok,项目名称:miranda-ng,代码行数:81,代码来源:dropbox.cpp


注:本文中的HttpRequest::AddHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。