언어 설정

Menu
Sites
Language
Http Post ProcessListeners
void
HttpRequestHelper::GetContent(void)
{    
    AppLog("GetContent.");

    result r = E_SUCCESS;
	HttpSession* pSession = null;
	HttpTransaction* pTransaction = null;
	String hostAddr(L"http://www.somesite.com");

	pSession = new HttpSession();
	r = pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, null, hostAddr, null);

	pTransaction = pSession->OpenTransactionN();
	r = pTransaction->AddHttpTransactionListener(*this);

	// Get the request instance.
	HttpRequest* pRequest = pTransaction->GetRequest();
	// Set the uri.
	r = pRequest->SetUri(L"http://www.somesite.com/do");

	// Set the method.
	NetHttpMethod method = NET_HTTP_METHOD_POST;
	r = pRequest->SetMethod(method);

	String sessionKey = "";
	const char* pBodyArray = "<body><getContent><sid></sid></getContent></body>";

	HttpHeader* pHeader = null;
	pHeader = pRequest->GetHeader();
	// Add the content-length to header.
	r = pHeader->AddField(L"Content-Type", L"application/xml");
	r = pHeader->AddField(L"User-Agent", L"SomeUserAgent==");
	r = pHeader->AddField(L"Accept", L"text/xml");
	int len = strlen(pBodyArray);
	String contentLength = Integer::ToString(len);
	String msg1 = "contentLength : " + contentLength;
	AppLog("%ls", msg1.GetPointer());
	r = pHeader->AddField(L"Content-Length",  contentLength);
	r = pHeader->AddField(L"Transfer-Encoding", L"chunked");

	pTransaction->EnableTransactionReadyToWrite();

	ByteBuffer reqBody;
	reqBody.Construct(len);
	reqBody.SetArray((byte*)pBodyArray, 0, len);
	reqBody.Flip();
	pRequest->WriteBody(reqBody);

	AppLog("Submitting.");
	pTransaction->Submit();
}

void HttpRequestHelper::OnTransactionReadyToRead(HttpSession& httpSession, HttpTransaction& httpTransaction, int availableBodyLen){
    AppLog("OnTransactionReadyToRead");
}
void HttpRequestHelper::OnTransactionAborted(HttpSession& httpSession, HttpTransaction& httpTransaction, result r){
	AppLog("OnTransactionAborted(%s)", GetErrorMessage(r));
	delete &httpTransaction;
}
void HttpRequestHelper::OnTransactionReadyToWrite(HttpSession& httpSession, HttpTransaction& httpTransaction, int recommendedChunkSize){
	AppLog("OnTransactionReadyToWrite");
}
void HttpRequestHelper::OnTransactionHeaderCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction, int headerLen, bool bAuthRequired){
	AppLog("OnTransactionHeaderCompleted");
}
void HttpRequestHelper::OnTransactionCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction){
	AppLog("OnTransactionCompleted");
	delete &httpTransaction;
}
void HttpRequestHelper::OnTransactionCertVerificationRequiredN(HttpSession& httpSession, HttpTransaction& httpTransaction, Tizen::Base::String* pCert){
	AppLog("OnTransactionCertVerificationRequiredN");
	httpTransaction.Resume();
	delete pCert;
}
bool HttpRequestHelper::OnTransactionCertVerificationRequestedN(HttpSession& httpSession, HttpTransaction& httpTransaction, Tizen::Base::Collection::IList* pCertList){
	AppLog("OnTransactionCertVerificationRequestedN");
	return true;
}

Hello there,

I've started development with Tizen recently, and i am trying to consume a Web Service that returns XML content.

I was able to construct the POST HttpRequest and call it successfully (Wireshark shows the request and the response correctly). However, something goes wrong when the IHttpTransactionEventListener event are being called (im guessing....), because in the stack strace the last log is something like :

Tizen::Base::Runtime::_Event::ProcessListeners(std::tr1::shared_ptr<Tizen::Base::Runtime::IEventArg>) + 0x41a (0xb460286a) [/usr/lib/osp/libosp-appfw.so] + 0x1b386a

I am using the emulator.

Also, no Callback events from IHttpTransactionEventListener  are being called.

Can someone help me out with this? Has anyone had the same problem?

Many Thanks

Nuno

Edited by: nuno filipe on 23 9월, 2014

Responses

10 댓글
Alex Ashirov

Hello,

Have you tried HTTPClient sample delivered with SDK? Does it work in your environment?

nuno filipe

Hi ALex,

Yes it works! Thx.

Not sure what i am doing wrong, but now, at least, i have something to base on.

Regards

Nuno

 

Jirka Prazak

Did you set the transaction listener to the object where you are listening on?  That would be the object that implements the http transaction listener, it would look something like this

r = pTransaction->AddHttpTransactionListener(*this);

-J

nuno filipe

Yes, i have.

My guess is, for this to work, the entity that calls the HttpRequest method must maintain a reference to the object until the listeneres are called back. Otherwise, the http request is executed, but the listeners are not invoked....

Anusha Sajeendran

Hi,

Please help me to make a network request  and response in Tizen Native App.  I have tried using connection_create() and connection_get_type() functions.

I am not sure how to handle the connections.

Alex Ashirov

Hi,

If you want HTTP request/response in the Tizen SDK 2.3. then you need to use Curl library:

http://curl.haxx.se/libcurl/c/

Alex Dem

Hi,
Unfortunately such example like HttpClient in 2.2.1 is missed in 2.3.
Alexey.

Alex Ashirov

Right, but you can find a lot of curl samples here:

http://curl.haxx.se/libcurl/c/example.html

Anusha Sajeendran

Hi,

Can anyone help me to send a request to a server and get the response.

This is the code i have used to check whether it is hitting the URL or not.

static void clicked_cb(void *data_, Evas_Object *obj, void *event_info) {
  char *data= "name=anusha&project=nativeapp";
  CURL *easyhandle;
  CURLcode result;
  curl_global_init(CURL_GLOBAL_ALL);
  easyhandle = curl_easy_init();

  if (easyhandle){
  curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, data);
  curl_easy_setopt(easyhandle, CURLOPT_URL, "www.google.com");
  curl_easy_perform(easyhandle);
        if(result == CURLE_OK){
      	  /*fprintf(stderr, "curl_easy_perform() success: %s\n", curl_easy_strerror(result));*/
  		  elm_exit();
  		 /* return;*/
  	  }
  }
  else{
	  fprintf(stderr, "Curl init failed:!\n" );
	  return;
  }
  curl_easy_cleanup(easyhandle);
  curl_global_cleanup();
  system("PAUSE");
  return;
}

 

Sathya Priya R

Hi Anusha,

Were you able to get it working and get successful OK response?

Help me with this.

I'm facing similar issues and getting CURLE_COULDNT_RESOLVE_HOST response.

Thanks,

Sathya Priya R