Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. use LWP::UserAgent;
  2.  
  3. my $ua = LWP::UserAgent->new;
  4.  
  5.  
  6. # set custom HTTP request header fields
  7.  
  8. my $req = HTTP::Request->new(PUT => "https://thesite.com");
  9.  
  10. $req->header('Authorization' => 'myauth');
  11. $req->header('Accept' => 'JSON:Application/JSON');
  12. $req->header('Content-Type' => 'JSON:Application/JSON');
  13. $req->header('Host' => 'api.thesite.com');
  14.  
  15. $req->content('Text' => 'thetext');
  16.  
  17.  
  18.  
  19. my $resp = $ua->request($req);
  20. if ($resp->is_success) {
  21. my $message = $resp->decoded_content;
  22. print "Received reply: $messagen";
  23. }
  24. else {
  25. print "HTTP POST error code: ", $resp->code, "n";
  26. print "HTTP POST error message: ", $resp->message, "n";
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement