1

I use the Qt v5.5. I need http get a request like this

QUrlQuery urlQuery;
urlQuery.setQuery("https://lalala.com/login");
urlQuery.addQueryItem("submit", "");
urlQuery.addQueryItem("email", "email@email.com");
urlQuery.addQueryItem("pass", "unbelievable_password");

when I call urlQuery.query(); the url is

"https://lalala.com/login&submit=&email=email@email.com&pass=unbelievable_password"

the param "submit" is the first param, it need use '?' split the param name, but the param is split by '&'.

Jobsz
  • 13
  • 3

2 Answers2

1

Looks like there's been discussion here on SO already. In general it looks as though any "sub-delims" should be accepted with or without a value: https://www.rfc-editor.org/rfc/rfc3986#appendix-A

Truth is, it's too bad that the QUrlQuery doesn't have the option for a value-less query without a trailing equal sign

Community
  • 1
  • 1
Son-Huy Pham
  • 1,899
  • 18
  • 19
1

You want to get the URL into a QUrl, then add query items on that -- and not have the URL as a query item itself!

QUrl url("https://www.foo.com");

QUrlQuery query;
query.addQueryItem("email", "foo@bar.com");
query.addQueryItem("pass", "secret");

url.setQuery(query);

qDebug() << url;

Correctly prints

QUrl("https://www.foo.com?email=foo@bar.com&pass=secret")
peppe
  • 21,934
  • 4
  • 55
  • 70