0

I'm creating win32 application and I work with one particular site. From previous requests I extracted some cookies and I want to implement them. But the problem is, one of these cookies contains unicode letter (latyn small letter e with dot above; 279 in ASCII table). It is the only cookie which is url-encoded. When decoding, I get char \u0117 and visual studio compiler gives me warning that it is unicode char and treats it as ? mark.

This is url-encoded cookie:

Set-Cookie: logged_user=%7B%22id%22%3A%22625936%22%2C%22email%22%3A%22vytautas.leveris%40gmail.com%22%2C%22display_name%22%3A%22Vytautas+L%5Cu0117veris%22%2C%22full_name%22%3A%22Vytautas+L%5Cu0117veris%22%2C%22photo%22%3A%22https%3A%5C%2F%5C%2Fwww.15min.lt%5C%2Fassets%5C%2Fimages%5C%2Fuser-default-icon.png%22%2C%22photo_small%22%3A%22https%3A%5C%2F%5C%2Fwww.15min.lt%5C%2Fassets%5C%2Fimages%5C%2Fuser-default-icon.png%22%2C%22photo_normal%22%3A%22https%3A%5C%2F%5C%2Fwww.15min.lt%5C%2Fassets%5C%2Fimages%5C%2Fuser-default-icon.png%22%2C%22staff%22%3Afalse%2C%22bookmarks%22%3A2%2C%22nb%22%3A1%7D; path=/

This is url-decoded cookie:

Set-Cookie: logged_user={\"id\":\"625936\",\"email\":\"vytautas.leveris@gmail.com\",\"display_name\":\"Vytautas L\u0117veris\",\"full_name\":\"Vytautas L\u0117veris\",\"photo\":\"https:\/\/www.15min.lt\/assets\/images\/user-default-icon.png\",\"photo_small\":\"https:\/\/www.15min.lt\/assets\/images\/user-default-icon.png\",\"photo_normal\":\"https:\/\/www.15min.lt\/assets\/images\/user-default-icon.png\",\"staff\":false,\"bookmarks\":2,\"nb\":1}; path=/

And finally, all http GET request:

strcpy(request,"GET / HTTP/1.1\r\nHost: www.15min.lt\r\nCookie: PHPSESSID=652e6dd2ac78de5db5392e53b9a0355a; logged_user={\"id\":\"625936\",\"email\":\"vytautas.leveris@gmail.com\",\"display_name\":\"Vytautas L\u0117veris\",\"full_name\":\"Vytautas L\u0117veris\",\"photo\":\"https:\/\/www.15min.lt\/assets\/images\/user-default-icon.png\",\"photo_small\":\"https:\/\/www.15min.lt\/assets\/images\/user-default-icon.png\",\"photo_normal\":\"https:\/\/www.15min.lt\/assets\/images\/user-default-icon.png\",\"staff\":false,\"bookmarks\":2,\"nb\":1}; remember_me=625936; device_token_625936=84c45e719fedc5949ced93ca0df54152\r\nUser-Agent: WindowsSockets2\r\n\r\n");

As I send message through winsock, I use char type.

Do I need to convert everything to wchar_t*? But then what about sending wchar_t* to server? Or perhaps I could change this character representation \u0117 into UTF8 char sequence? Any help and comments would be welcom.

Usman
  • 1,983
  • 15
  • 28

1 Answers1

0

I'd recommend to treat the data as opaque sequence of bytes, i.e., convert you custom data to UTF-8 bytes, run base 64 and use it as cookie value. See also: https://stackoverflow.com/a/49205256/696632. Then reverse the operation on the receiver side. You will probably require unsigned char*for the opaque byte data.

Michael-O
  • 18,123
  • 6
  • 55
  • 121