Re: Question about soup_form_request_new() functions



On 27/06/2011 21:46, John Palmieri wrote:
> Yes, those are all pretty much unscriptable APIs except for the hash. You would need to request a new API from the libsoup devs.  I suggest one that takes a GSList of strings where the even entries and the 0 entry are names and the odd entries are values.

Thanks! I ended up asking just about the same question on
libsoup-list gnome org and Dan suggested building the SoupMessage
from scratch for now.

For those looking to do something similar, here's the relevant part
of what I came up with (using libsoup-2.34.2):

#!/usr/bin/env python

from gi.repository import Soup

uri = 'http://someplace-you-need-to-post'
parameters = {'series': ['X', 'Y', 'Z'], 'p': 'somevalue'}

session = Soup.Session()
session.add_feature_by_type(Soup.CookieJar)
cookiejar = session.get_feature(Soup.CookieJar)
cookiejar.set_accept_policy(Soup.CookieJarAcceptPolicy.ALWAYS)

request_body = []

for key, value in parameters.iteritems():
  if isinstance(value, list):
    request_body.append(Soup.form_encode_hash({key: x}) for x in value])
  else:
    request_body.append(Soup.form_encode_hash({key: value})

request_body = '&'.join(request_body)

message = Soup.Message.new('POST', uri)
message.set_request('application/x-www-from-urlencoded',
                    Soup.MemoryUse.COPY,
                    request_body,
                    len(request_body))
session.send_message(message)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]