1

I need to fill in a query with a username and password. An example is this: cgi-bin/videostream.cgi?user=&pwd=

However, these queries are not standardised so in another example, the keys could actually look like cgi-bin/videostream.cgi?passwd=&usr= .

Is there a clean solution that allows me to fill in these queries without using countless if/else statements? It is not possible to standardise the queries.

user1945317
  • 107
  • 9
  • how you want to fill? from text field? from string? – Teja Nandamuri Apr 15 '15 at 14:48
  • I probably wasn't clear in my explanation. With user=%@&pwd=%@, the issue isn't filling, but rather recognising when it's asking for user or password, because the keys can variate between a lot of options like user=&pwd=, usr=&pw=, userAccount=&userPassword= and sometimes they swap the keys around, making password the first key like this: passwd=&usr=. My question is whether it's possible to have a clean method that is able to figure out when the key is a password and when it's a user key. An example I thought of was checking for a u or p after the question mark, but this isn't very clean – user1945317 Apr 16 '15 at 09:50
  • 1
    http://stackoverflow.com/questions/2753956/how-do-i-check-if-a-string-contains-another-string-in-objective-c You could use that check for `&u`, `&p`, `?u`, `?p` – Pimgd Apr 17 '15 at 13:10

1 Answers1

1

Split on ?, then split on &.

The first string will be something like cgi-bin/videostream.cgi, the second like user=&pwd= or passwd=&usr=. Then, if you split on & you will get user= and pwd=, or passwd= and usr=. You can then freely append the parameters and concatenate the string.

Pimgd
  • 5,505
  • 1
  • 26
  • 44