如果此代码正确并在 asp 中工作
String xmlstc = "Some XML Code";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(server);
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = xmlstc.Length;
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());
streamWriter.Write(xmlstc);`
我想在 PHP 中使用 curl 实现同样的功能。下面的代码是否正确?
$xmlrequest = 'some xml code'
$server = ''
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
"Content-length: ".strlen($requestXML)
//"Connection: close",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXML);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);