使用PHP发布到远程服务器但收到404错误

时间:2016-04-22 08:21:29

标签: php curl

当我使用vardump将curl数据发布到php文件时,我得到404错误或白屏。但是,如果我将同一个文件放在服务器上,该文件上还有curl post文件,那么它可以工作。这是帖子的代码:

<?php



$imp = new DOMImplementation();
$xml_data = $imp->createDocument(
    null, 
    'cXML',  
    $imp->createDocumentType('cXML', 
        null, 
        'http://xml.cXML.org/schemas/cXML/1.2.008/cXML.dtd'
    )
);
$xml_data->xmlVersion="1.0";
$xml_data->encoding="UTF-8";


$root = $xml_data->createElement("cXML");
$xml_data->appendChild($root);


$rootAttributePayload = $xml_data->createAttribute("payloadID");
$root->appendChild($rootAttributePayload);


    $cXMLOrder = $xml_data->saveXML();
            $cXMLOrder = htmlspecialchars($cXMLOrder, ENT_QUOTES);

            $data = array('cXML-urlencoded' => $cXMLOrder);

            $ch = curl_init();

            $return_url1 = 'http://www.thisisanexample.net/POST_TEST.php';
            curl_setopt($ch, CURLOPT_URL, $return_url1);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt( $ch, CURLOPT_POSTFIELDS,   $data);
            // receive server response ...
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);



            curl_setopt($ch, CURLOPT_VERBOSE, true);

            $verbose = fopen('php://temp', 'w+');
            curl_setopt($ch, CURLOPT_STDERR, $verbose);

            $result = curl_exec($ch);
if ($result === FALSE) {
    printf("cUrl error (#%d): %s<br>\n", curl_errno($ch),
           htmlspecialchars(curl_error($ch)));
}

rewind($verbose);
$verboseLog = stream_get_contents($verbose);

echo "Verbose information:\n<pre>", htmlspecialchars($verboseLog), "</pre>\n";
            curl_close ($ch);

            // further processing ....
            if ($server_output == "OK") {echo "worked"; } else { echo "error"; }




?>

这是调试信息:

* Hostname was found in DNS cache
* Hostname in DNS cache was stale, zapped
*   Trying 195.8.209.135...
* Connected to www.example.net (195.8.209.135) port 80 (#0)
> POST //POST_TEST.php HTTP/1.1
Host: www.example.net
Accept: */*
Content-Length: 357
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------ba541b7fbc0d6707

< HTTP/1.1 404 Not Found
< Cache-Control: private
< Content-Type: text/html; charset=utf-8
< Server: Microsoft-IIS/8.5
< Date: Fri, 22 Apr 2016 08:03:13 GMT
< Content-Length: 4921
* HTTP error before end of send, stop sending
< 
* Closing connection 0

编辑:看起来如果我将此代码放在另一台curl post工作的服务器上。 任何人都可以解释发生了什么?

0 个答案:

没有答案