Suche in diesem Bereich
Inhaltsverzeichnis dieser Seite
CURL-Kommandozeile
CURL
cat request.xml | curl -X POST -H 'Content-Type: application/xml' --data-binary @- 'https://gateway.autodns.com'
Perl-Client (LWP)
Perl
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $debug=0; my $ua = LWP::UserAgent->new(); my $req = HTTP::Request->new( POST => 'https://gateway.autodns.com' ); $ua->agent('AgentName/0.1 ' . $ua->agent); $ua->timeout(1200); $req->content_type('application/xml'); my $content = do { local $/; <STDIN> };; $req->content($content); print STDERR "HTTP Request (".localtime()."):\n" if $debug; my $res = $ua->request($req); if ($res->is_success) { print $res->decoded_content()."\n"; print STDERR "HTTP Response:\n".$res->as_string()."\n\n" if $debug; } else { print STDERR $res->status_line()."\n"; }
PHP-Client (für PHP 4 und PHP 5 via cURL)
PHP
<?php define( 'HOST', 'https://gateway.autodns.com' ); define( 'XML_FILE', 'request.xml' ); $xml = implode( "", file(XML_FILE) ); header( 'Content-Type: application/xml' ); echo requestCurl( $xml ); function requestCurl( $data ) { $ch = curl_init( HOST ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, true ); if( !$data = curl_exec( $ch )) { echo 'Curl execution error.', curl_error( $ch ) ."\n"; return false; } curl_close( $ch ); return $data; } ?>
Java-Client
Java
import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.Charset; /** * Communicates with the backend. * * @author * */ public class Communicator { private static final String BACKEND_URL = "https://gateway.autodns.com/;" private static final Charset utf8Charset = Charset.forName("UTF-8"); /** * sends the given request to the predefined backend url via http post and reads the response * * @param request * @return */ public String sendRequest(String request) { URL url; HttpURLConnection connection = null; try { byte[] requestBytes = request.getBytes(utf8Charset); // Create connection url = new URL(BACKEND_URL); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/xml"); connection.setRequestProperty("HTTP-Version", "HTTP/1.0"); connection.setRequestProperty("Content-Length", "" + Integer.toString(requestBytes.length)); connection.setRequestProperty("Content-Language", "de-DE"); connection.setRequestProperty("charset", "utf-8"); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); // Send request DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream()); dataOutputStream.write(requestBytes); dataOutputStream.flush(); // Get Response InputStream is = connection.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; StringBuffer response = new StringBuffer(); while((line = reader.readLine()) != null) { response.append(line); response.append('\r'); } return response.toString(); } catch(Exception e) { e.printStackTrace(); return null; } finally { if(connection != null) { try { connection.getOutputStream().close(); connection.getInputStream().close(); } catch(Throwable e) { } connection.disconnect(); } } } }
Alternativ kannst du den folgenden Client verwenden: http://hc.apache.org/httpcomponents-client-ga/examples.html
Overview
Content Tools