本文整理汇总了C++中HttpRequest::SetMethod方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpRequest::SetMethod方法的具体用法?C++ HttpRequest::SetMethod怎么用?C++ HttpRequest::SetMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest::SetMethod方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: User
void
ProjectGiraffeTab1::updateItems()
{
#if kDebugUseDummyItems
AppLog("Creating dummy items");
User *dummyUser = new User();
dummyUser->setUsername(L"Username");
for (int i = 0; i < 10; i++) {
Graffiti *graffiti = new Graffiti();
graffiti->setUser(dummyUser);
graffiti->setText(L"dummy string");
_items->Add(graffiti);
}
#else
#if kDebugUseHttpConnection
double latitude = ProjectGiraffeMainForm::currentLatitude;
double longitude = ProjectGiraffeMainForm::currentLongitude;
HttpConnection *connection = HttpConnection::graffitiNearbyGetConnection(this,latitude,longitude);
connection->begin();
#else
// Kick off http request for items based on location.
// Populate item source array
HttpSession* pHttpSession = null;
HttpTransaction* pHttpTransaction = null;
String* pProxyAddr = null;
String hostAddr = L"http://ec2-54-243-69-6.compute-1.amazonaws.com/";
String uri = L"http://ec2-54-243-69-6.compute-1.amazonaws.com/";
AppLog("Starting the HTTP Session");
pHttpSession = new HttpSession();
// HttpSession construction.
pHttpSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, pProxyAddr, hostAddr, null);
// Open a new HttpTransaction.
pHttpTransaction = pHttpSession->OpenTransactionN();
// Add a listener.
pHttpTransaction->AddHttpTransactionListener(*this);
// Get an HTTP request.
HttpRequest* pHttpRequest = pHttpTransaction->GetRequest();
// Set the HTTP method and URI:
pHttpRequest->SetMethod(NET_HTTP_METHOD_GET);
pHttpRequest->SetUri(uri);
// Submit the request:
pHttpTransaction->Submit();
#endif
#endif
}
示例2: getTrip
String IRailConnection::getTrip(String &from, String &to,TrainsResultsForm *pTrainsResultsForm) {
this->pTrainsResultsForm = pTrainsResultsForm;
result r = E_SUCCESS;
String* pProxyAddr = null;
String hostAddr = L"http://api.irail.be";
String hostAddr2(L"http://api.irail.be/connections/?to=");
hostAddr2.Append(to);
hostAddr2.Append(L"&from=");
hostAddr2.Append(from);
HttpSession* pSession = null;
HttpTransaction* pTransaction = null;
pSession = new HttpSession();
r = pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, pProxyAddr ,hostAddr,null);
if (IsFailed(r))
{
AppLog("Construct Session failed. (%s)\n", GetErrorMessage(r));
}
pTransaction = pSession->OpenTransactionN();
if (null == pTransaction)
{
AppLog("Construct Session failed. \n");
}
r = pTransaction->AddHttpTransactionListener(*this);
if (IsFailed(r))
{
AppLog("AddHttpTransactionListener Session failed.\n");
}
HttpRequest* pRequest = pTransaction->GetRequest();
if(pRequest == null)
{
AppLog("GetRequest failed. \n");
}
r = pRequest->SetUri(hostAddr2);
if(IsFailed(r))
{
AppLog("SetUri failed. (%s)\n", GetErrorMessage(r));
}
r = pRequest->SetMethod(NET_HTTP_METHOD_GET);
if(IsFailed(r))
{
AppLog("SetMethod failed. (%s)\n", GetErrorMessage(r));
}
r = pTransaction->Submit();
if(IsFailed(r))
{
AppLog("Submit failed. (%s)\n", GetErrorMessage(r));
}
return hostAddr;
}
示例3: HttpSession
void
Network::IsReachable(const String& hostAddr) {
String* pProxyAddr = null;
//String hostAddr = L"http://localhost:port";
AppLogDebug("Trying to reach...%S", hostAddr.GetPointer());
__pHttpSession = new HttpSession();
__pHttpSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, pProxyAddr, hostAddr, null);
HttpTransaction* pHttpTransaction = __pHttpSession->OpenTransactionN();
pHttpTransaction->AddHttpTransactionListener(*this);
HttpRequest* pHttpRequest = pHttpTransaction->GetRequest();
pHttpRequest->SetMethod(NET_HTTP_METHOD_GET);
pHttpRequest->SetUri(hostAddr);
pHttpTransaction->Submit();
}
示例4: hostAddr
void
UserProfileForm::SendRequestGet(String requestUrl)
{
result r = E_SUCCESS;
HttpRequest* pRequest = null;
String hostAddr(L"https://graph.facebook.com");
if(__pSession == null)
{
__pSession = new HttpSession();
r = __pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, null, hostAddr, null);
if (IsFailed(r))
{
AppLog("Fail to HttpSession::Construct. [%s]", GetErrorMessage(r));
return;
}
__pSession->SetAutoRedirectionEnabled(true);
}
__pTransaction = __pSession->OpenTransactionN();
if (__pTransaction)
{
result r = __pTransaction->AddHttpTransactionListener(*this);
pRequest = __pTransaction->GetRequest();
if (pRequest)
{
pRequest->SetUri(requestUrl);
pRequest->SetMethod(NET_HTTP_METHOD_GET);
r = __pTransaction->Submit();
AppLog("RequestUrl is =%ls",requestUrl.GetPointer());
if(IsFailed(r))
{
AppLog("Fail to HttpRequest::Submit. [%s]", GetErrorMessage(r));
}
}
else
{
delete __pTransaction;
__pTransaction = null;
}
}
}
示例5: Request
bool HttpClient::Request(HttpRequest::MethodType method,
const std::string& url,
const std::string& data,
const HttpClient::Options& options,
HttpResponse *response,
ErrorCode *error)
{
ErrorCode error_placeholder;
if (error == NULL) {
error = &error_placeholder;
}
HttpRequest request;
request.SetMethod(method);
request.SetBody(data);
request.SetHeader("Content-Length", IntegerToString(data.size()));
DownloadTask task(this);
bool ret = task.ProcessRequest(url, options, &request, response);
*error = task.GetLastError();
return ret && *error == SUCCESS;
}
示例6: RequestHttpPost
result Chatting::RequestHttpPost(void) {
result r = E_SUCCESS;
HttpSession* pSession = null;
HttpTransaction* pTransaction = null;
HttpRequest* pRequest = null;
HttpMultipartEntity* pMultipartEntity = null;
String hostAddr(HTTP_CLIENT_HOST_ADDRESS);
// Creates an HTTP session.
pSession = new HttpSession();
r = pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, null, hostAddr, null);
pTransaction = pSession->OpenTransactionN();
r = pTransaction->AddHttpTransactionListener(*this);
// r = pTransaction->SetHttpProgressListener(*this);
pRequest = pTransaction->GetRequest();
pRequest->SetMethod(NET_HTTP_METHOD_POST);
r = pRequest->SetUri(HTTP_CLIENT_REQUEST_URI);
pMultipartEntity = new HttpMultipartEntity();
r = pMultipartEntity->Construct();
String me = __pEditField->GetText();
Tizen::Text::Encoding* pEnc = Tizen::Text::Encoding::GetEncodingN(L"UTF-8");
pMultipartEntity->AddStringPart(L"message", me, L"text/plain", L"UTF-8",
*pEnc);
r = pMultipartEntity->AddStringPart(L"friendIdRegId", resultRegId);
r = pRequest->SetEntity(*pMultipartEntity);
r = pTransaction->Submit();
return r;
}
示例7: ngx_http_cxxmvc_handler
static ngx_int_t ngx_http_cxxmvc_handler(ngx_http_request_t *r)
{
using dragon::kHttp_Method_Get;
using dragon::kResponseTypeRedirect;
using dragon::HeaderList;
using dragon::CookieList;
using dragon::StringRef;
using dragon::HttpRequest;
using dragon::HttpResponse;
ngx_buf_t *buf = NULL;
ngx_chain_t out;
unsigned uriLen = r->uri.len;
if (r->args.len > 0)
uriLen = r->uri.len + r->args.len + 1;
struct sockaddr_in *sin;
ngx_addr_t addr;
addr.sockaddr = r->connection->sockaddr;
addr.socklen = r->connection->socklen;
sin = (struct sockaddr_in *)addr.sockaddr;
char *ip = inet_ntoa(sin->sin_addr);
StringRef IP(ip, strlen(ip));
StringRef routingUrl((const char *)r->uri.data, uriLen);
StringRef userAgent;
if (r->headers_in.user_agent)
userAgent = StringRef((const char *)r->headers_in.user_agent->value.data, r->headers_in.user_agent->value.len);
std::string userCookie = ngx_http_get_cookie(r);
std::string lang = ngx_http_get_language(r);
HttpRequest req;
HttpResponse res;
req.SetMethod(kHttp_Method_Get);
req.SetUrl(routingUrl);
req.SetIp(IP);
//req.SetHost(StringRef(host, strlen(host)));
req.SetUserAgent(userAgent);
req.SetUserCookie(StringRef(userCookie.c_str(), userCookie.length()));
req.SetAcceptLanguage(StringRef(lang.c_str(), lang.length()));
req.ParseCookie();
DE.ResponseRequest(req, res);
ngx_str_t k = ngx_string("X-Powered-By");
ngx_str_t v = ngx_string("cxxmvc/0.1");;
ngx_http_add_header(r, &v, &k);
if (res.GetResponseType() == kResponseTypeRedirect)
{
ngx_str_t k = ngx_string("location");
ngx_str_t v = {res.GetContent().length(), (u_char *)res.GetContent().c_str()};
ngx_http_add_header(r, &v, &k);
}
HeaderList headers = res.GetHeaders();
if (headers.size() > 0)
{
HeaderList::iterator iter;
HeaderList::iterator end = headers.end();
for (iter = headers.begin(); iter != end; ++iter)
{
ngx_str_t k;
ngx_str_t v;
k.data = (u_char *)ngx_pcalloc(r->pool, iter->first.length()+1);
k.len = iter->first.length();
strcpy((char *)k.data, (const char *)iter->first.c_str());
v.data = (u_char *)ngx_pcalloc(r->pool, iter->second.length()+1);
v.len = iter->second.length();
strcpy((char *)v.data, (const char *)iter->second.c_str());
// std::cout << "key : "<< k.data << std::endl;
// std::cout << "value : " << v.data << std::endl;
ngx_http_add_header(r, &v, &k);
}
}
CookieList cookies = res.GetCookies();
if (cookies.size() > 0)
{
CookieList::iterator iter;
CookieList::iterator end = cookies.end();
for (iter = cookies.begin(); iter != end; ++iter)
{
ngx_str_t v;
v.data = (u_char *)ngx_pcalloc(r->pool, iter->length()+1);
v.len = iter->length();
strcpy((char *)v.data, (const char *)iter->c_str());
ngx_http_add_cookie(r, v);
}
}
//.........这里部分代码省略.........
示例8: hostAddr
HttpThread::HttpThread(std::string const & url,
downloader::IHttpThreadCallback & callback,
int64_t beg,
int64_t end,
int64_t size,
string const & pb)
: m_callback(callback),
m_begRange(beg), m_endRange(end),
m_downloadedBytes(0), m_expectedSize(size),
m_url(url), m_pb(pb),
m_pSession(0),
m_pTransaction(0)
{
result r = E_SUCCESS;
String * pProxyAddr = 0;
String hostAddr(m_url.c_str());
HttpHeader * header = 0;
LOG(LDEBUG, ("Creating HttpSession", m_url));
m_pSession = new HttpSession();
r = m_pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, pProxyAddr, hostAddr, header);
if (r != E_SUCCESS)
{
LOG(LERROR, ("HttpSession Construction error:", r));
return;
}
// Open a new HttpTransaction.
m_pTransaction = m_pSession->OpenTransactionN();
if ((r = GetLastResult()) != E_SUCCESS)
{
LOG(LERROR, ("OpenTransactionN", GetLastResult()));
return;
}
m_pTransaction->AddHttpTransactionListener(*this);
m_pTransaction->SetHttpProgressListener(*this);
HttpRequest * pRequest = m_pTransaction->GetRequest();
pRequest->SetUri(m_url.c_str());
HttpHeader * pHeader = pRequest->GetHeader();
// use Range header only if we don't download whole file from start
if (!(m_begRange == 0 && m_endRange < 0))
{
if (m_endRange > 0)
{
LOG(LDEBUG, (m_url, "downloading range [", m_begRange, ",", m_endRange, "]"));
String range("bytes=");
range.Append(m_begRange);
range.Append('-');
range.Append(m_endRange);
pHeader->AddField(L"Range", range);
}
else
{
LOG(LDEBUG, (m_url, "resuming download from position", m_begRange));
String range("bytes=");
range.Append(m_begRange);
range.Append('-');
pHeader->AddField("Range", range);
}
}
// set user-agent with unique client id only for mapswithme requests
if (m_url.find("mapswithme.com") != string::npos)
{
static string const uid = GetPlatform().UniqueClientId();
pHeader->AddField("User-Agent", uid.c_str());
}
if (m_pb.empty())
{
pRequest->SetMethod(NET_HTTP_METHOD_GET);
}
else
{
pRequest->SetMethod(NET_HTTP_METHOD_POST);
pHeader->AddField("Content-Type", "application/json");
int64_t const sz = m_pb.size();
String length;
length.Append(sz);
pHeader->AddField("Content-Length", length);
ByteBuffer body;
body.Construct((const byte *)m_pb.c_str(), 0, sz, sz);
pRequest->WriteBody(body);
}
LOG(LDEBUG, ("Connecting to", m_url, "[", m_begRange, ",", m_endRange, "]", "size=", m_expectedSize));
m_pTransaction->Submit();
}