Ich habe einen einfachen Webservice, mit dem ich mich verbinden möchte. Um einige XML
, die auf der Web-Service-Seite ordnungsgemäß fortgesetzt werden, zu veröffentlichen, muss ich eine ordnungsgemäße Anfrage vorbereiten. Ich verwende cURL
für diese wie folgt aus:PHP cURL Content-Type ist nicht gesetzt
try {
$ch = curl_init();
if (FALSE === $ch)
throw new Exception('failed to initialize');
curl_setopt($ch, CURLOPT_URL,"192.168.1.37");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/xml',
'Connection: Keep-Alive'
));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_PROXY, '');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Expect: "));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS,$xml);
$request= curl_getinfo($ch);
var_dump($request);
$content = curl_exec($ch);
if (FALSE === $content)
throw new Exception(curl_error($ch), curl_errno($ch));
} catch(Exception $e) {
trigger_error(sprintf(
'Curl failed with error #%d: %s',
$e->getCode(), $e->getMessage()),E_USER_ERROR);
}
Alles in Ordnung sein sollte. Zuerst zeige ich den Anfragetext von curl_getinfo($ch);
an und dann zeige ich die Antwort von $content
Variable.
Einzige Einschränkung für die Anforderung an den Server gesendet werden soll Content-Type
Header - es muss seine application/xml
sonst Server mit einem Fehler reagieren (Es ist nicht meine Idee ist, und ich kann nicht etwas dagegen tun)
Hier ausgegeben Anfrage:
array(21) { ["url"]=> string(68) "192.168.1.37" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(0) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0) ["namelookup_time"]=> float(0) ["connect_time"]=> float(0) ["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0) ["redirect_time"]=> float(0) ["certinfo"]=> array(0) { } }
und Antwort ist HTTP 400 Bad Request
Was ich von dem istsehenaber ich setze diese Variable in meinem PHP-Code ...
Kann mir jemand sagen, was ich vermisse?
Versuchen Sie, diesen Beitrag zu sehen: [http://stackoverflow.com/questions/9823810/set-http-request-content-type](http://stackoverflow.com/questions/9823810/set-http- Anfrage-Content-Type) –