Schrift
[thread]11693[/thread]

Problem bei cURL Aufrufen... (Seite 2)

Leser: 1


<< |< 1 2 >| >> 20 Einträge, 2 Seiten
tschloss
 2008-04-29 10:21
#108968 #108968
User since
2008-04-21
30 Artikel
BenutzerIn
[default_avatar]
Habe mit so großen Dateien leider keine Erfahrung.
Aber ich würde in besonderen Fällen mal bei LWP::UserAgent (die "unsimple" Version) stöbern.
Beim ersten Reinschauen traf ich auf diese Aussage:

If you set the $DYNAMIC_FILE_UPLOAD variable (exportable) to some TRUE value, then you get back a request object with a subroutine closure as the content attribute. This subroutine will read the content of any files on demand and return it in suitable chunks. This allow you to upload arbitrary big files without using lots of memory. You can even upload infinite files like /dev/audio if you wish; however, if the file is not a plain file, there will be no Content-Length header defined for the request. Not all servers (or server applications) like this. Also, if the file(s) change in size between the time the Content-Length is calculated and the time that the last chunk is delivered, the subroutine will Croak.

Quelle: http://search.cpan.org/~gaas/libwww-perl-5.69/lib/... ganz unten.
GwenDragon
 2008-04-29 11:37
#108972 #108972
User since
2005-01-17
14836 Artikel
Admin1
[Homepage]
user image
Und siehe auch bei den PerlMönchen unter http://www.perlmonks.org/?node_id=436544 ein weiteres Beispiel ;)
~Br4inP4in~
 2008-04-30 16:00
#109026 #109026
User since
2007-06-13
28 Artikel
BenutzerIn
[default_avatar]
Danke, das hat mir geholfen. Ich habe jetzt alle Module bis auf eines auf LWP umgestellt und sie funktionieren soweit.
Nun habe ich noch ein kleines Problem: Beim letzten übrigen Modul muss ein
Cookie für den Request gesetzt sein. In Curl sah der Aufruf so aus:
Code (perl): (dl )
$result = qx(curl -s -b 'auth=$login$md5_password' -F 'file1x=\@$file' '$server');

Hier noch die Info zum -b:
Code: (dl )
-b/--cookie <name=string/file> Cookie string or file to read cookies from


Hat jemand einen Beispielcode wie ich das verwirklichen kann?
Ich hoffe ihr könnt mir helfen, per Google findet man nicht wirklich viel dazu...

Gruß, ~Br4inP4in~
Gast Gast
 2008-05-01 02:44
#109062 #109062
$ua->cookie_jar([$cookie_jar_obj])

Get/set the cookie jar object to use. The only requirement is that the cookie jar object must implement the extract_cookies($request) and add_cookie_header($response) methods. These methods will then be invoked by the user agent as requests are sent and responses are received. Normally this will be a HTTP::Cookies object or some subclass.

The default is to have no cookie_jar, i.e. never automatically add "Cookie" headers to the requests.

Shortcut: If a reference to a plain hash is passed in as the $cookie_jar_object, then it is replaced with an instance of HTTP::Cookies that is initalized based on the hash. This form also automatically loads the HTTP::Cookies module. It means that:

$ua->cookie_jar({ file => "$ENV{HOME}/.cookies.txt" });

is really just a shortcut for:

require HTTP::Cookies;
$ua->cookie_jar(HTTP::Cookies->new(file => "$ENV{HOME}/.cookies.txt"));
~Br4inP4in~
 2008-05-01 13:26
#109066 #109066
User since
2007-06-13
28 Artikel
BenutzerIn
[default_avatar]
Hi.
Darauf bin ich auch gestoßen, jedoch dachte ich, ich könne den Cookie auch direkt
setzen (ohne Filehandle). Geht das auch irgendwie?
Wenn nicht, dann muss ich doch den Cookie vorher in mein Cookiefile, das ich bei
Code (perl): (dl )
$ua->cookie_jar({ file => "cookiefile.txt" });
angebe, schreiben?
Kann mir da jemand die Syntax nennen, die der Cookie im File haben muss?
Danke schonmal.

Gruß, ~Br4inP4in~
renee
 2008-05-01 14:56
#109069 #109069
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Code (perl): (dl )
$ua->cookie_jar( HTTP::Cookies->new() );
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
~Br4inP4in~
 2008-05-01 20:39
#109073 #109073
User since
2007-06-13
28 Artikel
BenutzerIn
[default_avatar]
renee+2008-05-01 12:56:11--
Code (perl): (dl )
$ua->cookie_jar( HTTP::Cookies->new() );


Aber bei HTTP::Cookies->new() hab ich doch nur diese Parameter:
Code: (dl )
1
2
3
4
  file:            name of the file to restore cookies from and save cookies to
autosave: save during destruction (bool)
ignore_discard: save even cookies that are requested to be discarded (bool)
hide_cookie2: do not add Cookie2 header to requests


Kann ich dort auch direkt cookiedaten angeben?
Oder muss ich den Cookie mit
Code (perl): (dl )
$cookie_jar->set_cookie( $version, $key, $val, $path, $domain, $port, $path_spec, $secure, $maxage, $discard, \%rest )

setzen? Muss ich dann diese ganzen Angaben machen, Curl braucht die ja auch nicht?
Mir wäre ein kleines Beispiel zum Cookie aktivieren, setzen und die Anfrage
mit Cookie abschicken ganz recht, irgendwie steig ich da nicht so ganz durch... :(

Gruß, ~Br4inP4in~
renee
 2008-05-02 10:48
#109086 #109086
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Normalerweise wird ja ein Cookie von der aufgerufenen Seite geliefert. Wenn Du mit
Code (perl): (dl )
$ua->cookie_jar( HTTP::Cookies->new )
dem $ua ein Cookie-Objekt übergeben hast, dann kümmert sich LWP schon von alleine um das Cookie-Handling. D.h. das Cookie wird automatisch gesetzt und bei allen weiteren Abfragen wird das Cookie automatisch mitgeschickt.
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
~Br4inP4in~
 2008-05-02 15:45
#109101 #109101
User since
2007-06-13
28 Artikel
BenutzerIn
[default_avatar]
Das Problem ist aber, dass der Cookie bei der Nutzung der 1CH-API nicht direkt
gesetzt wird, sondern man das mehr oder weniger selbst in die Hand
nehmen muss.
Da ich gern die API nutzen möchte, um eine langfristige Nutzung zu gewährleisten,
muss ich den Cookie selbst setzen.
Er soll dann eben als Key "auth" und als Value "$login.$md5_password" enthalten.

Gruß, ~Br4inP4in~
~Br4inP4in~
 2008-05-02 20:38
#109116 #109116
User since
2007-06-13
28 Artikel
BenutzerIn
[default_avatar]
Okay, ich habs hinbekommen. Danke nochmal an alle!

Hier meine "Lösung" für die Nachwelt ;)
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
my $cookie_jar = HTTP::Cookies->new();
my $ua = LWP::UserAgent->new;
$cookie_jar->set_cookie(undef, 'auth', $login.$md5_password, '/', $server, undef, 0, 0, 60*60, 0);
my $req = POST $server,
            [file1x => [$file]],
            'Content_Type' => 'form-data';
$cookie_jar->add_cookie_header($req);
my $result = $ua->request($req);
my $return = $result->content;


Hab im Netz ein Beispiel gefunden, das mir geholfen hat, hab leider den
Link nicht mehr...
Naja, wie gesagt, vielen Dank nochmal an alle, ihr habt mir sehr geholfen :)

Gruß, ~Br4inP4in~
<< |< 1 2 >| >> 20 Einträge, 2 Seiten



View all threads created 2008-04-23 18:03.