语言

Menu
Sites
Language
http client get method querystring

Hi to all,

I need support to understand how Tizen manages querystring.

I create a project native http client as the HttpClient shows, but when I try to use an URL with a query string as "http://server/path/program?query_string", the Submit method failed with the error message "01-08 21:59:18.025 : ERROR / Tizen::Net::Http ( 8073 : 8073 ) : result Tizen::Net::Http::_HttpTransactionImpl::Submit()(556) > [E_INVALID_ARG] [SECURE_LOG] The host address(http://mymemory.translated.net) of HttpSession is different with url(http://mymemory.translated.net/api/get?q=Ciao&langpair=it|ko)."

On the other hand, if I submit a request with URL without querystring (in my test "http://mymemory.translated.net/api/get"), the submit works fine, but obviously I get an error message by the server.

Could someone help me to understand how manage querystring?

Thanks in advance

Regards

Dario

 

响应

3 回复
Alex Dem

Hi,
try to use HttpMultipartEntity:

https://developer.tizen.org/dev-guide/2.2.1/org.tizen.native.appprogramming/html/tutorials/net_tutorial/uploading_HTTP_multipart_data.htm

your requsted uri will be:
const static wchar_t* HTTP_CLIENT_REQUEST_URI = L"http://mymemory.translated.net/api/get";

and you could configure your querystring in http post method this way:

  HttpMultipartEntity* pMultipartEntity = null;
  pMultipartEntity = new HttpMultipartEntity();
  pMultipartEntity->Construct();
  pMultipartEntity->AddStringPart(L"q", L"hello");
  pMultipartEntity->AddStringPart(L"langpair", L"en|it");
  r =  pHttpRequest->SetEntity(*pMultipartEntity);

I have checked. It works.
Alexey.

Alex Ashirov

Hi,

The problem is that the URI must be encoded properly according to RFC 2396. This means that symbols like "|" should be escaped. For example, you should use "%7C" instead of "|". Also, you can use solution above proposed by Alexey.

Dario Lo Giudice

Thanks, I forgot to escape special and reserved characters according to RFC 2396. Usually, the simplest solution is the best one and the last that attempted.

Regards