"POST" method for search form

Any trouble you encounter with the Pedias, here's the place to ask for help.
Post Reply
User avatar
Rigido
Addicted to Bruji
Addicted to Bruji
Posts: 139
Joined: Mon Dec 03, 2007 8:07 am
Location: Acilia, Rome, Italy

"POST" method for search form

Post by Rigido »

Hi Devs,
I was thinking to write a new plugin for an Italian site (DVDweb.it, it looks like it is a good reference for EAN, even for older DVDs) but looks like the search form uses a POST method.

Code: Select all

<form action="https://www.dvdweb.it/index.mv?Ricerca_TITA_2" method="post" name="ricercadvdwebnavi">
Is it possible to handle POST method from the plugins?

Ciao.
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: "POST" method for search form

Post by Conor »

There is a helper method included in the plugin framework for post methods. First construct the body for the post out of all the forms "name" "value" pairs joined by ampersand (&) and then use downloadWebPage:withPost:encoding: on self. In this case it would be something like:

Code: Select all

NSString *postBody = [NSString stringWithFormat:@"loc_ricerca=barra_navigazione&supporto=DVD&titolo=%@&genere=0", searchString];

	[self downloadWebPage:@"https://www.dvdweb.it/index.mv?Ricerca_TITA_2" withPost:postBody encoding:NSISOLatin1StringEncoding];
You could make the value of "supporto" also dependent on the media field and change that with a variable to "BRD" if you desired.
User avatar
Rigido
Addicted to Bruji
Addicted to Bruji
Posts: 139
Joined: Mon Dec 03, 2007 8:07 am
Location: Acilia, Rome, Italy

Re: "POST" method for search form

Post by Rigido »

Conor,
I think that should be withPost:postBody.
I put a stringlimit to let user choose between DVD, BR, Original Title, Director, Writer or Actor, so this is what I did:

Code: Select all

NSString *postBody = [NSString stringWithFormat:@"loc_ricerca=barra_navigazione&supporto=%@&titolo=%@&genere=0", stringLimit, aString];

[self downloadWebPage:@"https://www.dvdweb.it/index.mv?Ricerca_TITA_2" withPost:postBody encoding:NSISOLatin1StringEncoding];
Search works (resultsSection is loaded, still trying to narrow values) but page is a mess, everything is between am href and a </b>, there are no "classes" or a keywords to help with parsing.
I wrote to DVDWeb info, hope they are interested and will help as DVDStore did.

Ciao.
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: "POST" method for search form

Post by Conor »

I think that should be withPost:postBody.
Would be a more appropriate name but since not all plugins are made by me it's hard to change names now. I could have a deprecated function with the old name, but not worth the trouble.
User avatar
Rigido
Addicted to Bruji
Addicted to Bruji
Posts: 139
Joined: Mon Dec 03, 2007 8:07 am
Location: Acilia, Rome, Italy

Re: "POST" method for search form

Post by Rigido »

Conor,
maybe I didn't understand the syntax but:
if I use withPost:encodedString, Xcode gives me 2 issues: "Use of undeclared identifier EncodedString; did you mean typeEncodedString?" and "Incompatible integer to pointer conversion sending "int" to parameter of type "NSString *".
On the first example, you initialized the postBody NSString that's why I thought that that should be the name to use with withPost...and that works too :)
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: "POST" method for search form

Post by Conor »

You are 100% right, I misunderstood the withPost:postBody comment (I read it as the method should have had a name of withPost:postBody:encoding: instead of downloadWebPage:withPost:encoding:).

The code you posted would be the correct format. The actual declaration of the helper method is this one to clear up confusion:

Code: Select all

- (void)downloadWebPage:(NSString *)aWebPage withPost:(NSString *)body encoding:(int)anEncoding;
It had a variable (encodedString) from were I took the original code that does not exist in the sample above. Rarely (because it's a mistake) a page might require the body to be encoded. Found this out with two plugins and they have a middle line that does:

Code: Select all

NSString *encodedString = [postBody stringByAddingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];
Use your version of the code. I have updated my answer to avoid the typo as well.
Post Reply